How can I enable the aptoma twig-markdown extension? I have installed it using composer
but when I use {% markdown %}
in my twig file, I get an error message saying:
Unexpected "markdown" tag (expecting closing tag for the "block" tag defined near line 8).
I had a look in the symfony documentation but was not able to find the solution.
Edit:
I tried to add the following code to services.yml
but got another error:
twig.markdown:
class: Aptoma\Twig\Extension\MarkdownExtension
arguments: []
tags:
- { name: twig.extension }
Type error: Argument 1 passed to Aptoma\Twig\Extension\MarkdownExtension::__construct() must be an instance of Aptoma\Twig\Extension\MarkdownEngineInterface, none given [...]
Upon request my .twig
-file:
{% extends 'XYZBundle::layout.html.twig' %}
{% block title %}
{{ parent() }} – Eintrag anzeigen
{% endblock %}
{% block platform_body %}
<ul>
<li>
<a href="{{ path('work_index') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('work_edit', { 'id': work.id }) }}">Edit</a>
</li>
</ul>
<h1>{{ work.title }}</h1>
<div class="work-content">
{% markdown %}
{{ work.content }}
{% endmarkdown %}
</div>
{% endblock %}
According to the docs you need to install the markdown engine of your choice like:
You need to create a service for the twig extension and the markdown engine, add the engine to the extension and register it as twig extension, f.e like this in your services.yml or config.yml:
Symfony will then automatically register it as twig extension through the usage of 'tags' or tagged services.