Template Conditions

From MozillaWiki
Jump to: navigation, search

Conditions are done using a <where> tag in a rule.

 <conditions>
   <where var="?var"
          rel="contains"
          value="value"
          ignorecase="true"
          negate="true"
          multiple="true"/>
 </conditions>

Each condition is evaluated in sequence for a result. Conditions evaluate to either true or false. If all conditions evaluate to true, there is a match and the corresponding action body is used to generate content for that result. The remaining rules are ignored in this case. If any rule evaluates to false, the condition does not match and the next rule is evaluated.

A where condition is a simple comparison between the value of the 'var' attribute and the value of the 'value' attribute. Both attributes may be either strings or variables. The operator to use is specified by the 'rel' attribute. There are eight operators available:

  • equals: the two values are equal
  • less: the numeric value of var is less than than value
  • greater: the numeric value of var is less than than value
  • before: the string value of var is before value
  • after: the string value of var is before value
  • startswith: the value of var starts with value
  • endswith: the value of var ends with value
  • contains: the value of var contains value

The negate attribute may be set to true to negate the operator, that is, for example, startswith will become 'not startswith'.

The ignorecase attribute may be set to true to ignore case when comparing strings.

The multiple attribute may be set to true to indicate that 'value' is a comma-separated list of strings. The condition will match as long as one of the values matches.

The var, rel and value attributes are required. The negate, ignorecase and multiple attributes default to false.