[#if condition]
body
[/#if]
or
[#if condition]
body
[#else]
body
[/#else][/#if]
where:
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).
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()]
[/#if]
Features [foreach f in myClass.feature]
${f.name}
[/#foreach]
The above code would produce an output similar to the following:
| Features |
| firstName |
| lastName |
| address |
This code prints an alternative message if there is no feature:
[if ! myClass.feature.isEmpty()]
[#else]No feature[/#else]Features [foreach f in myClass.feature]
${f.name}
[/#foreach]
[/#if]