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
footer.markdown.twig
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.
Note:
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
<?php
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)
{
parent::__construct($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/default.md containing the markdown/content