Converts text with Markdown syntax into HTML in Twig templates.
- Stuart Chapman stuart.chapman@admin.cam.ac.uk
-
Add TwigMarkdowner to your dependencies
// composer.json { // ... "require": { // ... "misd/twig-markdowner": "1.0.*" } }
-
Use Composer to download and install TwigMarkdowner
$ php composer.phar update misd/twig-markdowner
-
Instantiate a
MarkdownParser
and add the extension to the Twig environment$parser = new \dflydev\markdown\MarkdownParser(); /** @var $twig Twig_Environment */ $twig->addExtension(new Misd\TwigMarkdowner\Twig\Extension\MarkdownerExtension($parser));
In a Twig template:
{{ "My *Markdown* text"|markdown }}
or
{{ object.property|markdown }}
This filter does not prevent the injection of arbitrary HTML and JavaScript; the output should be filtered (using HTMLPurifier, or equivalent) before being output in a template.