Branching Macros

Branching macros provide if-then-else constructs. The CTF supports a limited form of branching through these macros:

  • if
  • elseIf
  • else
  • endIf
  • 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:

  • ==
  • !=
  • <   (mathematics comparison, less than)
  • >   (mathematics comparison, greater than)
  • <= (mathematics comparison, less than or equal to)
  • >= (mathematics comparison, greater than or equal to)

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

Note that if you are using one of the mathematics comparison operators, <test> must be a decimal number in string format.

Branches can be nested, and multiple conditions can be specified using one of:

  • and, or
  • or

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) and 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)%

     %if $fldType4 == "date"%



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.

Example 1

%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

Example 2



%if $bases !="" and $interfaces !=""%

: $bases, $interfaces

%elseIf $bases !=""%

: $bases

%elseIf $interfaces !=""%

: $interfaces


In this case the text returned is ':ClassBase'.

Conditions using Boolean Value

When setting up 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"%

For example:

     % if attCollection == "T" or attOrderedMultiplicity == "T" %

     % endTemplate %

Learn more