An if-else structure looks like this:
<if condition> Some HTML... </if>
Or like this:
<if condition> Some HTML... <else> Some other HTML... </if>
Elseifs are also allowed, as follows:
<if condition1> HTML for condition 1... <elseif condition2> HTML for condition 2... <elseif condition3> HTML for condition 3... </if>
The condition
should be a boolean
expression. For example:
<if !(color == "blue" || color == "violet")> You have an unusual favorite color. </if> <if foo && (!(bar || baz) || elephant)> Tweedledee. </if>
Since undefined, null, and empty values evaluate to false, it is convenient to use idioms like the following:
<if error> <p>Your request cannot be processed because of the following error:<br> ${error} <else> (display results...) </if>
Since undefined, null, and empty values are considered equal, the
following two statements are equivalent, whether foo
is defined or not:
<if foo> ... </if> <if foo != ""> ... </if>
Previous: Lists | Next: Switch-Case |