GWC Template Language Reference / Template Expressions |
Template expressions respect a defined syntax:
{ 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 | built-in | null | undefined }
boolean_expression ? if_true : if_false
{ ! | + | - }
{ arithmetic_op | boolean_op | comparison_op }
{ * | / | % | + | - }
{ < | <= | > | >= | == | != }
{ && | || }
{ TRUE | FALSE }
' string '
_tpl_
{ [ expression [, ...] ] }argument_list can be empty.
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
fct is any valid function name
<div class="gContainer" gwc:attributes="class _tpl_+' gTag'+tag"> will produce <div class="gContainer gTagMYTAG"> assuming tag has MYTAG as valueThe built-in expression _tpl_ gets the previous value of an attribute before it is changed by the gwc:attributes instruction. In this snippet, _tpl_ refers the class attribute value, that is: gContainer.
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 |
*Evaluation is done like the test made by the gwc:condition instruction
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 falseAs 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
The in operator is used to look for a string value in a string value list. Elements of the list are separated by a space character
'bill' in 'bob bill john' # produces true