gondo
gondo

Reputation: 1128

whats the difference between {% vs {%- in twig?

as can be seen here https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig some of the if conditions are written as:

{% if condition %}

but others are written as:

{%- if condition -%}

my code works perfectly fine with both versions. unfortunately its impossible to google the answer as google doesn't like no alphanumeric chars in query very much, also i did not find any reference in twig documentation.

my question is, whats the difference between those two?

whats the meaning of the dash in {%- ?

Upvotes: 37

Views: 18142

Answers (1)

Maerlyn
Maerlyn

Reputation: 34125

It is related to twig's whitespace control. By using the whitespace control modifier on your tags, you can trim leading and/or trailing whitespace. Here are the docs.

Upvotes: 43

Related Questions