if / elif / else commands
if / elif / else commands
if / elif / else commands are used for conditional rendering. These commands control whether a component is rendered. For example, the if command renders the component only when the condition is true; otherwise, it removes the component. This is different from the component's show attribute, which controls visibility without removing the component.
Syntax
if command
<p if="cond">if: true</p>
If the cond expression is true, the component will be rendered; otherwise, it will not be rendered.
elif and else commands
Components containing elif and else commands must follow a component containing an if or elif command, and use the negation of the previous condition to control whether the component is rendered:
<p if="cond1">if cond1: true</p>
<p elif="cond2">elif cond2: true</p>
<p elif="cond3">elif cond3: true</p>
<p else>else</p> <!-- The else command does not support attribute values -->
The behavior of this code is as follows:
- If the
cond1condition is true, only the textif cond1: truewill be rendered; - Otherwise, if
cond2is true, onlyelif cond2: truewill be rendered; - Otherwise, if
cond3is true, onlyelif cond3: truewill be rendered; - If all conditions are false, the
elsetext will be rendered.
The attribute values of if / elif / else commands support the command attribute value syntax.
