4 When writing Twig templates, we recommend you to follow these official coding
7 * Put one (and only one) space after the start of a delimiter (``{{``, ``{%``,
8 and ``{#``) and before the end of a delimiter (``}}``, ``%}``, and ``#}``):
14 {% if foo %}{% endif %}
16 When using the whitespace control character, do not put any spaces between
23 {%- if foo -%}{%- endif -%}
25 * Put one (and only one) space before and after the following operators:
26 comparison operators (``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``), math
27 operators (``+``, ``-``, ``/``, ``*``, ``%``, ``//``, ``**``), logic
28 operators (``not``, ``and``, ``or``), ``~``, ``is``, ``in``, and the ternary
35 {{ true ? true : false }}
37 * Put one (and only one) space after the ``:`` sign in hashes and ``,`` in
45 * Do not put any spaces after an opening parenthesis and before a closing
46 parenthesis in expressions:
52 * Do not put any spaces before and after string delimiters:
59 * Do not put any spaces before and after the following operators: ``|``,
60 ``.``, ``..``, ``[]``:
67 {% for i in 1..12 %}{% endfor %}
69 * Do not put any spaces before and after the parenthesis used for filter and
74 {{ foo|default('foo') }}
77 * Do not put any spaces before and after the opening and the closing of arrays
85 * Use lower cased and underscored variable names:
90 {% set foo_bar = 'foo' %}
92 * Indent your code inside tags (use the same indentation as the one used for
93 the main language of the file):