markdown function for Twig and Slim
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md

README.md

It's a quick and dirty snippet in order to add a markdown() function to Twig with Slim Framework via Parsedown by @erusev :

<?php
require DIR_VENDORS . 'Parsedown/Parsedown.php';
[...]
$twig = $app->view()->getEnvironment();
 
$function = new Twig_SimpleFunction('markdown', function ($text) {
    $mkparser = new Parsedown();
    return $mkparser->text($text);
});

$twig->addFunction($function);
[...]

Now, in your template file/Twig file :

{{ markdown(string)|raw }}

And voila!