The <ISIF>
tag group allows you to create conditional ISML code. <ISIF>
, and its supporting tags, <ISELSEIF>
and <ISELSE>
, will likely be the tags you use most in your templates. These are also called business flow functions because they control the business logic's flow.
Every <ISIF>
tag must have a matching </ISIF>
tag. <ISIF>
uses operators to compare values. For more information about operators, see Reference - ISML Operators. To perform more complex comparisons, you can combine conditions within parentheses using logical operators. You can compare any values accessible through variables, as well as numerical and string constants.
The <ISELSE>
and <ISELSEIF>
tags are optional. You may use as many <ISELSEIF>
tags as needed in an <ISIF>
statement, but you can only use one <ISELSE>
, which must always be the last comparison performed.
<isif condition = "{ISML expression}"> ... some HTML and ISML code ... [ <iselseif condition = "{ISML expression}"> ... some HTML and ISML code ... ]* [ <iselse> ... some HTML and ISML code ... ] </isif>
The example shows some possible conditional entries in a template (with and without using operators):
<isif condition="#hasLoopElements(Basket:ProductLineItems)#"> <isif condition="#isDefined(Error_PasswordConfirmation)#"> <isif condition="#Error_PasswordConfirmation EQ 'MandatoryValueNotAvailable'#"> <isif condition="#(isdefined(ERROR_FormValues)) OR (isdefined(ERROR_User))#"> <isif condition="#(isdefined(ERROR_FormValues) AND isdefined(ConfirmMail)) OR (not(isdefined(ERROR_FormValues)))#">
This example shows how to alternate the colors of the rows in a table. The current color is stored in the user-defined variable, color
.
<ISSET name="color" value="#'#00FFFF'#"> <table> <ISLOOP iterator="basket:product"> <tr> <td bgcolor="#color#"> <ISPRINT value = "#product:name#"> </td> </tr> <ISIF condition="#color EQ '#00FFFF'#"> <ISSET name="color" value="#'#00CCFF'#"> <ISELSEIF condition="#color EQ '#00CCFF'#"> <ISSET name="color" value="#'#0099FF'#"> <ISELSE> <ISSET name="color" value="#'#00FFFF'#"> </ISIF> </ISLOOP> </table>
The result of a conditional expression must be a Boolean value:
<ISIF condition ="#Products:Price==0#"> Special free gift. <ISELSEIF condition ="#Products:Price<100#"> Special deal. <ISELSE> Today’s low price. </ISIF>