mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-06 23:48:50 +00:00
added coding standards in the docs
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
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:: jinja
|
||||
|
||||
{{ foo }}
|
||||
{# comment #}
|
||||
{% if foo %}{% endif %}
|
||||
|
||||
When using the whitespace control character, Do not put any spaces between it
|
||||
and the delimiter:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{- foo -}}
|
||||
{#- comment -#}
|
||||
{%- if foo -%}{%- endif -%}
|
||||
|
||||
* Put one (and only one) space before and after the following operators:
|
||||
comparison operators (``==``, ``!=``, ``<``, ``>``, ``>=``, and ``<=``),
|
||||
math operators (``+``, ``-``, ``/``, ``*``, ``%``, ``//``, ``**``), ``~``,
|
||||
``is``, ``in``, ``not``, ``and``, ``or``, and the ternary operator (``?:``):
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ 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:: jinja
|
||||
|
||||
{{ [1, 2, 3] }}
|
||||
{{ {'foo': 'bar'} }}
|
||||
|
||||
* Do not put any spaces before and after string delimiters:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ 'foo' }}
|
||||
{{ "foo" }}
|
||||
|
||||
* Do not put any spaces before and after the following operators: ``|``,
|
||||
``.``, ``..``, ``[]``:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ foo|upper|lower }}
|
||||
{{ user.name }}
|
||||
{{ user[name] }}
|
||||
{% for in in 1..12 %}{% endfor %}
|
||||
|
||||
* Do not put any spaces before and after the parenthesis used for filter and
|
||||
function calls:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ 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:: jinja
|
||||
|
||||
{{ [1, 2, 3] }}
|
||||
{{ {'foo': 'bar'} }}
|
||||
|
||||
* Use lower cased and underscored variable names:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% set foo = 'foo' %}
|
||||
{% set foo_bar = 'foo' %}
|
||||
@@ -11,6 +11,7 @@ Twig
|
||||
extensions
|
||||
hacking
|
||||
recipes
|
||||
coding_standards
|
||||
tags/index
|
||||
filters/index
|
||||
functions/index
|
||||
|
||||
+2
-2
@@ -536,8 +536,8 @@ but exists for completeness' sake. The following operators are supported:
|
||||
* ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would
|
||||
return ``4``.
|
||||
|
||||
* ``**``: Raises the left operand to the power of the right operand. ``{{ 2**3
|
||||
}}`` would return ``8``.
|
||||
* ``**``: Raises the left operand to the power of the right operand. ``{{ 2 **
|
||||
3 }}`` would return ``8``.
|
||||
|
||||
Logic
|
||||
~~~~~
|
||||
|
||||
Reference in New Issue
Block a user