if, else

Syntax


[#if condition]
    body
[/#if]

or

[#if condition]
    body
[#else]
    body
[/#else][/#if]

where:

Description

The if and else tags conditionally skip a section of the template. The condition must evaluate to a boolean value.

The else tag is optional and may occur only inside an if (that is, between the if start-tag and end-tag).

Examples

This code will output a text only if the UML class is abstract:

[if myClass.isAbstract]
    the class is abstract
[/#if]

This code will output a table with the name of each feature of a UML class, only if there's at least one feature:

[if ! myClass.feature.isEmpty()]
Features
[foreach f in myClass.feature]
${f.name}
[/#foreach]
[/#if]

The above code would produce an output similar to the following:

Features
firstName
lastName
address
email

This code prints an alternative message if there is no feature:

[if ! myClass.feature.isEmpty()]
Features
[foreach f in myClass.feature]
${f.name}
[/#foreach]
[#else]No feature[/#else]
[/#if]