From 3cf36bbefa1c659861ef3376f3c4d97f1c9db844 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 2 Nov 2020 18:44:55 +0100 Subject: 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 --- tests/00_syntax/18_if_condition | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') 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: {% -- cgit v1.2.3