Skip to content

<if>/<else>

A pair of tags that conditionally render portions of the UI. If the test expression evaluates to true, the <if> tag's children are rendered. Otherwise, the <else> tag's children are rendered (if present). If the test expression evaluates to a non-bool value (including null), it is treated as false.

The <else> tag must be a direct child of an <if> tag. If placed elsewhere, it will be ignored.

Attributes

<if>

Name Type Description Required Default
test bool An EL expression returning a bool. Non-bool values are treated as false. Yes -

<else>

No attributes. The <else> tag is optional and must be a direct child of <if>.

Examples

Basic Conditional

<if test="${isLoggedIn}">
    <Text data="Welcome back, ${userName}!"/>
</if>

If/Else

<if test="${isLoggedIn}">
    <fragment name="dashboard"/>
    <else>
        <fragment name="login"/>
    </else>
</if>

Comparison Expressions

<if test="${user.role == 'admin'}">
    <fragment name="admin_panel"/>
    <else>
        <Text data="Access denied"/>
    </else>
</if>

Nested Conditionals

<if test="${items.length > 0}">
    <forEach var="item" items="${items}">
        <Text data="${item.name}"/>
    </forEach>
    <else>
        <Text data="No items found"/>
    </else>
</if>

Multiple Conditions

<Column>
    <if test="${user.isPremium}">
        <Text data="Premium Member"/>
    </if>
    <if test="${user.isAdmin}">
        <fragment name="admin_tools"/>
    </if>
</Column>

See Also

  • <forEach> - For iterating over collections
  • <fragment> - The visible attribute provides simpler conditional rendering
  • Expression Language - EL syntax reference