Extensions
Besides the translation, the package has these extensions for the templates. Add them in the extensions option of the service.
Markdown
Derafu\Twig\Extension\MarkdownExtension has the markdown filter, which renders Markdown with derafu/markdown (install it to use the extension):
{% verbatim %}
{{ text|markdown }}
{% endverbatim %}
With true, the Markdown can also have Twig code, which is rendered with the context of the template, and the tags of components, which the Markdown parser does not change:
{% verbatim %}
{{ text|markdown(true) }}
{% endverbatim %}
A content that PCRE can not process is a translatable error that says why.
Nested Twig
Derafu\Twig\Extension\TwigExtension has the twig filter, which renders a string as a template with the context of the one that uses it:
{% verbatim %}
{{ 'Hello {{ name }}'|twig }}
{% endverbatim %}
The result is not escaped.
Routes
Derafu\Twig\Extension\RoutingExtension has path(), url() and is_active_path(), over a router of derafu/routing (install it to use the extension):
use Derafu\Routing\Router;
use Derafu\Routing\ValueObject\RequestContext;
use Derafu\Twig\Extension\RoutingExtension;
$router = new Router();
$router->addRoute('docs', '/docs', 'handler');
$router->addRoute('post', '/blog/{slug}', 'handler');
$router->setContext(new RequestContext(host: 'example.com', scheme: 'https', pathInfo: '/docs/intro'));
$extension = new RoutingExtension($router);
{% verbatim %}
{{ path('post', {slug: 'hello'}) }} {# /blog/hello #}
{{ url('docs') }} {# https://example.com/docs #}
{{ url('docs', {}, true) }} {# //example.com/docs #}
{{ is_active_path('docs') }} {# true: /docs is the start of /docs/intro #}
{{ is_active_path('docs', {}, false) }} {# false: it is not exactly /docs #}
{% endverbatim %}
is_active_path() needs the context of the router (the current path): without it, it is a translatable error. The route reference scanner checks that the routes of a template exist.