Branching macros provide if-then-else constructs. The CTF supports a limited form of branching through the following macros:
|·||endTemplate (which exits the current template)|
The basic structure of the if and elseIf macros is:
%if <test> <operator> <test>%
where <operator> can be one of:
and <test> can be one of:
|·||a string literal, enclosed within double quotation marks|
|·||a direct substitution macro, without the enclosing percent signs|
|·||a variable reference|
Branches can be nested, and multiple conditions can be specified using one of:
When specifying multiple conditions, and and or have the same order of precedence, and conditions are processed left to right.
If conditional statements on strings are case sensitive, "a String" does not equal "A STRING". Hence in some situations it is better to set the variable $str= TO_LOWER(variable) or TO_UPPER(variable) then compare to a specific case.
Macros are not supported in the conditional statements. It is best to assign the results of a macro (string) to a variable, and then use the variable in the comparison.
$fldType = %TO_LOWER($parameter1)%
$COMMENT = "Use the first 4 characters for Date and Time field types"
$fldType4 = %LEFT($fldType,4)%
This takes a parameter of value �Datetime�, �DATETIME� or �Date�, and returns �Datetime�.
The endif or endTemplate macros must be used to signify the end of a branch. In addition, the endTemplate macro causes the template to return immediately, if the corresponding branch is being executed.
%if elemType == "Interface"%
In this case:
|·||If the elemType is "Interface" a semi-colon is returned|
|·||If the elemType is not "Interface", a template called Operation Body is called|
%if $bases !="" and $interfaces !=""%
: $bases, $interfaces
%elseIf $bases !=""%
%elseIf $interfaces !=""%
In this case the text returned is :ClassBase.
Conditions using Boolean Value
When doing branching using conditions that involve a system checkbox (boolean fields), such as Attribute.Static (attStatic) the conditional statement would be written as:
%if attStatic == "T"%
%if attCollection=="T" or attOrderedMultiplicity == "T"%