allmarkedup / twig-extensions
A few handy extensions for Twig.
Installs: 9 920
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- erusev/parsedown: ~1.1
- twig/twig: ~1.0
Requires (Dev)
- phpunit/phpunit: ~4.3
This package is not auto-updated.
Last update: 2024-11-19 04:10:45 UTC
README
A few handy extensions for Twig.
Included extensions:
Installation and use
Using composer:
$ composer require allmarkedup/twig-extensions
Then load the required extension(s) into the Twig environment when setting it up as per the instructions in the Twig docs. For example, to use the Markdown extension, you would use something like this:
<?php use Amu\Twig\TwigMarkdownExtension as MarkdownExtension; //... $twig = new Twig_Environment($loader, $options); $twig->addExtension(new MarkdownExtension());
Included extensions
Markdown Extension
The Markdown extension uses Parsedown under the hood to allow for easy Markdown -> HTML conversion in your templates.
To install:
<?php $twig->addExtension(new Amu\Twig\TwigMarkdownExtension());
Use it in your templates as a filter:
{{ 'This is a **string**' | markdown }}
Or use it as a tag:
{% markdown %}
_This sentence is emphasised_
> And this is a quote.
{% endmarkdown %}
Running tests
Tests can be run using PHP Unit:
$ vendor/bin/phpunit
The project also includes a Grunt watch task to run the PHP Unit tests when files are updated which you can use for your convenience.