Use Markdown in twig template

I’m using a a custom theme based on Learn2.
Want to use a footer in the sidebar written in Markdown (to use email obscuration plugin)

   <section id="footer">
  	{{ include('partials/footer.markdown.twig')|markdown_to_html }}

with some simple test 1 line in the footer file to try

[color=red]test footer[/color]

But nothing is displayed.
I struggle with twig and I’m sure there must be a simpler way.
Any help would be appreciated

You might try the Twig markdown_to_html filter.

To clarify, the <section … shown above was in the
sidebar.html.twig customisation of the Learn2 template.

it uses the Twig markdown_to_html filter on the included file
which contains the test line shown
I don;t know if my line of code is incorrect or markdown_to_html doesn’t work within the Grav implementation.

Do you have Shortcode Core enabled?


Try filter |markdown instead of |markdown_to_html
See Twig Filters | Grav Documentation

I’m not a fan of using Twig containing Markdown. I prefer to keep functional layers separate: Page content = Markdown, page layout = Twig, etc.

Remember that Twig will be transpiled into a PHP file (and cached), which will contain, amongst others, a function doDisplay() which echoes your Markdown. Eg. echo "# Hello world!";

Entire generated PHP file

use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;

/* partials/footer.markdown.twig */
class __TwigTemplate_58a49df49dc86a7170e4a043b7ff747fc552b4dca18d00964cae8907b276f81f extends \Twig\Template
    public function __construct(Environment $env)

        $this->parent = false;

        $this->blocks = [

    protected function doDisplay(array $context, array $blocks = [])
        // line 1
        echo "# Hello world!";

    public function getTemplateName()
        return "partials/footer.markdown.twig";

    public function getDebugInfo()
        return array (  30 => 1,);

    /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
    public function getSource()
        @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);

        return $this->getSourceContext()->getCode();

    public function getSourceContext()
        return new Source("# Hello world!", "partials/footer.markdown.twig", "/www/grav/site-dev/user/themes/quark/templates/partials/footer.markdown.twig");

You may have a compelling reason for using Markdown inside Twig of course.

I would prefer to keep layers separate and would therefor use something like:

  • A file containing reusable content, e.g. /user/pages/includes/footer/ containing the markdown/content
  • And use it inside any Twig template
    {{ page.find('/includes/footer').content | raw }}

Solved, the solution is simple and obvious when you see it.
I moved the markdown out of the twig file.

I knew what I was doing was a fudge but, still not got my head around twig template as I rarely need to modify them.

Thats why I love Grav. Generally it just works and support is excellent.