This filter (alternatively, t
) will run the variable through the Drupal t()
function, which will return a translated string. This filter should be used for any interface strings manually placed in the template that will appear for users.
<a href="{{ url('<front>') }}" title="{{ 'Home'|t }}" rel="home" class="site-logo"></a>
This filter escapes content to HTML and formats it using drupal_placeholder()
, which makes it display as emphasized text.
{% trans %}Submitted on {{ date|placeholder }}{% endtrans %}
Replace twig's escape filter with our own.
{{ items|safe_join(', ') }}
{{ content|without('links') }}
{{ content|without('links', 'field_some_data') }}
This filter prepares a string for use as a valid HTML class name. See Html::getClass()
{{ some_var|clean_class }}
This filter prepares a string for use as a valid HTML ID. See Html::getID()
{{ some_var|clean_id }}
{{ some_var|render }}
This filter prepares a timestamp for use as a formatted date string. See DateFormatter::format()
To use a Drupal date/time format:
{{ some_var|date('U')|format_date('long') }}
This filter should be avoided whenever possible, particularly if you're outputting data that could be user-entered. See this page for more information on auto-escape in Drupal 8.
{{ some_var|raw }}
{{ set some_var = some_var|merge(['item 1', 'item 2']) }}
{{ set some_var = some_var|merge({id: 'the_id'}) }}
{{ set some_var = some_other_var|default('The value to use if some_other_var is empty') }}