Back to Contents


Template Expressions

Topics


expressions syntax

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

  1. conditional_expression returns a value according to the result of a condition expression
    boolean_expression ? if_true : if_false
    If 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
  2. expression_as_string  is a string
  3. [ argument_list ] defines an array
    [ 1, 2, 'a', 'b' ]      # defines an array with 4 elements
  4. ( expression ) defines a priority in the processing of the expressions.
    (a + b) * c             # means expression 'a + b' will be processed before the result is multiplied by c
  5. fct is any valid function name
  6. string is a string value
  7. numeric is a numeric value
  8. expression_as_string is any template expression resulting in a string value
  9. template_path is any valid template path
  10. null expression removes a corresponding attribute
    title comment || null;  # if comment attribute is not an empty string 
                            # then set comment value to title otherwise 
                            # remove the html attribute title 
  11. undefined is the value returned by a template path when the path is not available. It is used to make the difference between a template path that would return an empty string and a path that does not exist in the current context.
  12. The + operator can be used with string values to concatenate two strings. Other operators will not work unless string values evaluate to numeric expressions:
    'This expression ' + 'works'
    '12' - '34'                       # works
    '12' - 'ab'                       # doesn't work
  13. The boolean operators && and || behave like their JavaScript equivalent. The following table gives the result of the expression:
    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 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
  14. 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
  15. 'bill' in 'bob bill john'         # produces true

Back to the top