Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 {%- ?

like image 746
gondo Avatar asked Nov 13 '13 01:11

gondo


People also ask

What is twig tag?

Twig tags are control structures that control the flow of the templates. They consist of conditionals (i.e. if/elseif/else), for loops, as well as blocks. Tags appear inside a pair of {% %} blocks. The closing {% %} block is "end" followed by the tag name.

How do I comment in a twig file?

twig command keyword is #. using inside of {# and end with #}. below is your needed answer.


1 Answers

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's the docs.

like image 142
Maerlyn Avatar answered Sep 23 '22 10:09

Maerlyn