File: coding_standards.rst

package info (click to toggle)
php-twig 3.5.1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,560 kB
  • sloc: php: 17,829; makefile: 106; sh: 42
file content (101 lines) | stat: -rw-r--r-- 2,374 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 ``#}``):

  .. code-block:: twig

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

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

  .. code-block:: twig

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

* Put one (and only one) space before and after the following operators:
  comparison operators (``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``), math
  operators (``+``, ``-``, ``/``, ``*``, ``%``, ``//``, ``**``), logic
  operators (``not``, ``and``, ``or``), ``~``, ``is``, ``in``, and the ternary
  operator (``?:``):

  .. code-block:: twig

     {{ 1 + 2 }}
     {{ foo ~ bar }}
     {{ true ? true : false }}

* Put one (and only one) space after the ``:`` sign in hashes and ``,`` in
  arrays and hashes:

  .. code-block:: twig

     {{ [1, 2, 3] }}
     {{ {'foo': 'bar'} }}

* Do not put any spaces after an opening parenthesis and before a closing
  parenthesis in expressions:

  .. code-block:: twig

    {{ 1 + (2 * 3) }}

* Do not put any spaces before and after string delimiters:

  .. code-block:: twig

    {{ 'foo' }}
    {{ "foo" }}

* Do not put any spaces before and after the following operators: ``|``,
  ``.``, ``..``, ``[]``:

  .. code-block:: twig

    {{ foo|upper|lower }}
    {{ user.name }}
    {{ user[name] }}
    {% for i in 1..12 %}{% endfor %}

* Do not put any spaces before and after the parenthesis used for filter and
  function calls:

  .. code-block:: twig

     {{ foo|default('foo') }}
     {{ range(1..10) }}

* Do not put any spaces before and after the opening and the closing of arrays
  and hashes:

  .. code-block:: twig

     {{ [1, 2, 3] }}
     {{ {'foo': 'bar'} }}

* Use lower cased and underscored variable names:

  .. code-block:: twig

     {% set foo = 'foo' %}
     {% set foo_bar = 'foo' %}

* Indent your code inside tags (use the same indentation as the one used for
  the target language of the rendered template):

  .. code-block:: twig

     {% block foo %}
         {% if true %}
             true
         {% endif %}
     {% endblock %}