What does the hyphen (dash) mean for a Twig block like in {% block body -%}?

A hyphen (or dash) at the end of a Twig block means to trim trailing whitespace, at the beginning, leading whitespace. Both means… both.

See the Whitespace Control section of the docs; their example:

{% set value="no spaces" %}
{#- No leading/trailing whitespace -#}
{%- if true -%}
    {{- value -}}
{%- endif -%}
{# output 'no spaces' #}

<li>
    {{ value }}    </li>
{# outputs '<li>\n    no spaces    </li>' #}

<li>
    {{- value }}    </li>
{# outputs '<li>no spaces    </li>' #}

<li>
    {{~ value }}    </li>
{# outputs '<li>\no spaces    </li>' #}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)