Control Constructions |
In the notification templates, the following control constructions can be used: 1. Custom Macro Declaration If required, you can declare custom macros directly in the template by using the following construction: <def NAME=DATA> where NAME – macro name (without a $ character), DATA – new macro value. Name of the macro can consist of characters in the [a-zA-Z_-] range. A new macro value can be quoted. The character that follows the back slash "\" is treated directly (that is, you can use this character to add, for example, a back angle bracket character). Example <def MY_MACROS="\<my macros\>"> In this example, the $MY_MACROS$ macro that contains '<my macros>' is declared. 2. Inserting External File Content You can add the external file content to the template by using the following directive <include FILENAME> where FILENAME – name and path to the file relative to the $TEMPLATES_DIR$ macro value. File name and file path can be quoted. The character that follows the back slash "\" is treated directly (that is, you can use this character to add, for example, a back angle bracket character). Example <include "style.css"> In this example, text from the style.css file is inserted in the stead of the directive. You can use conditional operators in the templates. The operators are defined as follows: <if NAME [ ( '==' | '!=' ) DATA ] > where NAME – macro name, DATA – regular expression to check the macro value (regular Perl expressions are used), TEXT – text to be inserted into the message if the condition is true. The following two conditional operators are available: •== - True if the macro value corresponds to the regular expression; •!= - True if the macro value does not correspond to the regular expression. If a part of the construction in square brackets is not specified (that is, the condition is <if NAME>), the construction is treated as <if NAME != "" >. Use of nested conditional operators is allowed (for details, see below). If the operator includes the def directive to declare a new macro, this macro is defined only if the conditional part is true. At that, a new macro value is saved and becomes available after the conditional operator is checked. Example <def N="n123"> In a notification generated from such a template, the following strings are inserted: N is not empty! 3. Loop You can use loops in the templates. A loop is specified as follows: <for NAME;LIST [ ( '==' | '!=' ) DATA ; [DELIM] ] > where •NAME – name of a macro that is used as a local variable in the loop body. Each time the loop iterates, another value retrieved from LIST is assigned to the variable. •LIST – macro used as a list of values for the local variable in the loop. Macro value can be a list. In this case, any macro can be specified; at that, if its value cannot be a list, the value is separated with commas and transformed into the list. •DATA – regular expression to check and select values from the list each time the loop iterates. •DELIM – delimiter inserted in the notification body between text fragments generated each time the loop iterates. If the values in square brackets are not specified, the construction is treated as <for NAME;LIST == ".*" >; that is, all values from LIST are used. Otherwise, each value form LIST is compared with the expression specified in DATA and if the result is true, (== - corresponds, а != - does not correspond), the next value is assigned to the NAME macro and the loop iterates. If DELIM is specified, the corresponding value selected as a delimiter is inserted into the notification. Loop processing consists of the following steps: 1)For each selected NAME, the following text is generated <def NAME="LIST_VAL"> where LIST_VAL – next value selected from LIST, and TEXT – text specified in the loop body. 2)For this text a syntax analyzer is called and the outcome of its operation is placed immediately after the <\for> label. 3)This operation is performed for each selected value from LIST. 4)Loop construction is removed from the generated notification and syntax analyzer starts parsing the result text. Example <def RCPTS="root@localhost, test@mydoamin.com"> The result text is the following: <a href="mailto:root@localhost">root@localhost</a>, All key words def, if and for are case insensitive. |