Coding Standards

Coding Standards

When writing Twig templates, we recommend you to follow these official coding standards:

  • Put one (and only one) space after the start of a delimiter ({{, {%, and {#) and before the end of a delimiter (}}, %}, and #}):

    {{ foo }}
    {# comment #}
    {% if foo %}{% endif %}
    

    When using the whitespace control character, do not put any spaces between it and the delimiter:

    {{- foo -}}
    {#- comment -#}
    {%- if foo -%}{%- endif -%}
    
  • Put one (and only one) space before and after the following operators: comparison operators (==, !=, <, >登录查看完整内容