Highlight source code directly from Twig templates with a tag or filter powered by ALTO Code Highlight.
Use the block tag for source written in a template or the filter for source provided by your application:
{% code_highlight 'php' %}
<?php echo 'Hello, Alto!';
{% endcode_highlight %}
{{ source|code_highlight('javascript') }}composer require alto/twig-code-highlightThe package requires PHP 8.4 or later, ALTO Code Highlight 1.x, and Twig 3.28 or later.
Contributions of all kinds are welcome. Visit the project on GitHub to report a bug, suggest a feature, or open a pull request.
Before submitting code, run:
# Runs PHP CS Fixer, PHPStan, and PHPUnit
composer qaChanges to public behavior should include tests and documentation.
ALTO Twig Code Highlight is open source and independently maintained by Simon André. If it is useful to your work, you can support its continued development through GitHub Sponsors.
Sharing the package or starring it on GitHub also helps.
ALTO Twig Code Highlight is released by ALTO PHP under the MIT License.