---
title: "Extensions"
description: "Extensions"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-10-20"
last_update: "2026-10-20"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/ui/twig/extensions"
---

# Extensions

Besides the [translation](translations), the package has these extensions for the templates. Add them in the `extensions` option of the [service](service).

## Markdown

`Derafu\Twig\Extension\MarkdownExtension` has the `markdown` filter, which renders Markdown with [`derafu/markdown`](https://www.derafu.dev/docs/ui/markdown) (install it to use the extension):

{% verbatim %}
```twig
{{ 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 %}
```twig
{{ 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 %}
```twig
{{ '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`](https://www.derafu.dev/docs/core/routing) (install it to use the extension):

```php
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 %}
```twig
{{ 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](lint#route-references) checks that the routes of a template exist.



---
Last updated on 20/10/2026

