diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-02 18:44:55 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-02 19:43:13 +0100 |
commit | 3cf36bbefa1c659861ef3376f3c4d97f1c9db844 (patch) | |
tree | 99c9e9d4eadf2a58aa1073532d22d57481c2c04a /tests | |
parent | f23fb27f949f28517bef5206a5773f08d8202ea8 (diff) |
syntax: support `elif` clauses for alternative `if` syntax
In the alternative `if` syntax mode, support a specific `elif` keyword instead
of requiring an `else` branch followed by a disjunct `if` statement.
The advantage is that templates do not require error-prone redundant `endif`
keywords in else-if ladders.
After this change, the following example:
{% if (...): %}
One condition
{% else if (...): %}
Another condition
{% else if (...): %}
A third condition
{% else %}
Final condition
{% endif; endif; endif %}
... can be simplified into:
{% if (...): %}
One condition
{% elif (...): %}
Another condition
{% elif (...): %}
A third condition
{% else %}
Final condition
{% endif %}
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/00_syntax/18_if_condition | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/00_syntax/18_if_condition b/tests/00_syntax/18_if_condition index 9601f11..9e02767 100644 --- a/tests/00_syntax/18_if_condition +++ b/tests/00_syntax/18_if_condition @@ -22,6 +22,10 @@ An if-condition using the alternative syntax: Variable x has another value. +An if-condition using the special "elif" keyword in alternative syntax mode: +Variable x was set to five. + + Ternary expressions function similar to if/else statements but only allow for a single expression in the true and false branches: Variable x is one @@ -93,6 +97,18 @@ Variable x has another value. {% endif %} +An if-condition using the special "elif" keyword in alternative syntax mode: +{% if (x == 0): -%} +Variable x was set to zero. +{% elif (x == 1): -%} +Variable x was set to one. +{% elif (x == 5): -%} +Variable x was set to five. +{% else -%} +Variable x has another value. +{% endif %} + + Ternary expressions function similar to if/else statements but only allow for a single expression in the true and false branches: {% |