Template expressions respect a defined syntax.
Syntax
expression is:
{ conditional_expression
| unary_op expression
| expression op expression
| expression_as_string in expression_as_string
| [ argument_list ]
| ( expression )
| fct ( argument_list )
| template_path
| numeric
| boolean
| string
| null
| undefined
}
where conditional_expression is:
boolean_expression ? if_true : if_false
where unary_op is:
{ ! | + | - }
where op is:
{ arithmetic_op | boolean_op | comparison_op
}
where arithmetic_op is:
{ * | / | % | + | - }
where comparison_op is:
{ < | <= | > | >= | == | != }
where boolean_op is:
{ && | || }
where boolean is:
{ TRUE | FALSE }
where string is:
' string '
where argument_list is a list of expressions separated by comas:
{ [ expression [, ...] ] }
argument_list can be empty.
Notes
boolean_expression ? if_true : if_falseIf the boolean_expression results in true, the conditional_expression returns the if_true expression, otherwise if_false is returned.
orientation=='horizontal'?'':' gRadioGroupVertical' # produces an empty string if orientation equals # horizontal, otherwise returns gRadioGroupVertical
[ 1, 2, 'a', 'b' ] # defines an array with 4 elements
(a + b) * c # means expression 'a + b' will be processed before the result is multiplied by c
title comment || null; # if comment attribute is not an empty string # then set comment value to title otherwise # remove the html attribute title
'This expression ' + 'works' '12' - '34' # works '12' - 'ab' # doesn't work
expr_A op expr_B
Operator | expr_A is TRUE* | expr_B is FALSE* |
&& |
expr_B | false |
|| |
expr_A | expr_B |
1 > 0 && 'expr_A is true' # produces expr_A is true 1 < 0 && 'expr_A is false' # produces 0 1 < 0 || 'expr_A is false' # produces expr_A is false
As the && operator's priority is greater than the || operator's priority, you can combine these operators to have an if … then … else … statement :
condition_expr && expr_if_true || expr_if_false
true && 'bill' || 'bob' # produces bill false && 'bill' || 'bob' # produces bob
'bill' in 'bob bill john' # produces true