← Configuration | Index
If you want to implement another Markdown parser library, you can.
Create the file src/AppBundle/Markdown/MyMarkdownParser
and write the following class :
<?php
namespace AppBundle\Markdown;
class MyMarkdownParser implements MarkdownParserInterface
{
function parse($string)
{
// The method will take as parameter the Markdown string and must return the rendered HTML
}
}
Now we have our parser, the class must be registered as service to be injected in the bundle.
Register the class as service in services.yml
with the tag markdown.parser
services:
# ...
my_markdown_parser:
class: AppBundle\Markdown\MyMarkdownParser
tags:
- { name: markdown.parser, alias: my_markdown_parser } # The alias attribute is required, it's the parser name
# ...
Now we can use the Twig filter markdown
with our new Markdown parser
{{ my_var | markdown('my_markdown_parser') }} {# The parser name is the alias of the service tag #}
← Configuration | Index