Expression Tokens

 

Expressions are special tokens that can be used within template files in order to include or exclude a piece of code based on some condition. There are several different types of expressions that can be used in different places within a template file. For example, there are expressions that can be used in a field loop which allow you to include or exclude sections of code based on the attributes of the field that is currently being processed.

There are two types of expressions:

Multi-line expressions cause one or more lines of output code to be included or excluded, based on the evaluation of the expression, and occur when the opening and closing conditional tags appear on separate lines in a template file, and delimit one or more entire lines of template code, like this:

<IF expression>
code
</IF[ expression]>

In-line expressions cause part of an output line to be included or excluded based on the evaluation of the expression, and occur when the opening and closing conditional tags appear on the same line in a template file, and delimit part of a line of template code, like this:

[code] <IF expression> code </IF[ expression]> [code]

Alternate Expression Closing Tags

In complex template files you may prefer to use an alternate format of the closing </IF> tag which includes the name of the condition. For example, if you are using an <IF INTEGER> expression you can chose to specify the closing tag as </IF INTEGER>. Doing so can help to make template files more readable.

Single ELSE Clauses

Single ELSE clauses allow you to test for both positive and/or negative matches to an expression, and are supported in multi-line expressions, like this:

<IF expression>
code
<ELSE>
code
</IF[ expression]>

And in in-line expressions, like this:

[code] <IF expression> code <ELSE> code </IF[ expression]> [code]

Multiple ELSE Clauses

Multiple ELSE clauses allow you to test several expressions at the same time, similar to using an "else if" construct in a programming language, and are supported in multi-line expressions, like this:

<IF expression_1>
code
<ELSE expression_2>
code
[<ELSE expression_n>
code]
</IF[ expression_1]>

And in in-line expressions, like this:

[code] <IF expression_1> code <ELSE expression_2> code [<ELSE expression_n> code]</IF[ expression]> [code]

When using multiple else clauses, all expressions must be of the same type. For example when using field loop expressions, you could use a construct like this:

<IF ALPHA>
code for alpha fields
<ELSE DECIMAL>
code for decimal fields
<ELSE INTEGER>
code for integer fields
</IF>

Nesting Expressions

Multi-line expressions may be nested within one another. For example:

<IF expression_1>
[code]
<IF expression_2>
code
</IF[ expression_2]>
[code]
</IF[ expression_1]>

In-line expressions may be nested within multi-line expressions.

<IF expression_1>
[code]
[code] <IF expression_2>code</IF[ expression_2]> [code]
[code]
</IF[ expression1]>

Multiple in-line expressions may be used within the same line:

[code] <IF expression_1>code</IF[ expression_1]> [code] <IF expression_2>code</IF[ expression_2]> [code]

In-line expressions may be embedded within one another:

[code] <IF expression_1>[code]<IF expression_2>code</IF[ expression_2]></IF[ expression_1]> [code]

Complex Expressions

Complex Expressions allow you to use AND, OR and NOT operators within expression tokens, and also allows you to use parentheses to explicitly define precedence. Here are some examples:

<IF expression_1 AND expression_2>
[code]
</IF>

<IF expression_1 OR expression_2>
[code]
</IF>

<IF NOT expression_1>
[code]
</IF>

<IF NOT expression_1 AND expression_2>
[code]
</IF>

<IF expression_1 AND (expression_2 OR expression_3)>
[code]
</IF>

<IF expression_1 OR expression_2>
[code]
<ELSE expression_3 AND expression_4>
[code]
<ELSE>
[code]
</IF>

 

 

 


Copyright © 2021  Synergex International, Inc.