isif Element

Create conditional template code and control the flow of business logic.

Syntax 

1<isif condition = if_expression>
2  ...
3 <iselseif condition = elseif_expression> //0 or more
4  ...
5 </iselseif>
6 <iselse>
7  ...
8</isif>
condition = if_expression

Allowed data type: string or expression.

if_expression evaluates to a boolean value. If the <isif> condition is true, the system executes the code immediately following the <isif> tag, ignoring the enclosed <iselseif> and <iselse> tags. If the <isif> condition is false, the system ignores the code immediately following the <isif> tag, and then tests each <iselseif> condition in order. When the system finds a true <iselseif> condition, the system executes the code immediately following the <iselseif> tag and ignores any remaining <iselseif> and <iselse> tags. If all <iselseif> conditions are false, the system executes the code following the <iselse> tag.

Purpose 

The <isif> tag group lets you create conditional programming constructs using custom tags.

Supporting Tags 

<isif> and its supporting tags, <iselseif> and <iselse>, are some of the most commonly used tags. They contain no business logic, just the conditional visualization of data.

Rules of Use 

Every <isif> tag must have a matching </isif> tag. You can use any Salesforce B2C Commerce script expression as a condition for the <isif> tag. In particular, you can use local variables, Pipeline Dictionary variables and any functions within those expressions.

<iselse> and <iselseif> are optional. You can use as many <iselseif> tags as needed in an <isif> statement, but you can only use one <iselse>, which must always be the last tag within an <isif> group.

Example 

A conditional expression should typically return a boolean which is interpreted appropriately. If condition expression evaluates to non boolean and is not null, it’s interpreted as true. When it evaluates to null it’s interpreted as false.

1<isif condition="${pdict.Products.Price == 0}">
2Special free gift.
3<iselseif condition="${pdict.Products.Price < 100}">
4Special deal.
5<iselse>
6Today's low price.
7</isif>

This example shows how to toggle continuously between three different colors for the rows of a table. The current color is stored in the user-defined variable, color.

1<isset name="color" value="${'#00FFFF'}" scope="PAGE">
2<table>
3<isloop iterator="${pdict.Basket.products} var="product">
4<tr>
5<td bgcolor="${product.color}">
6<isprint value = "${product.name}">
7</td>
8</tr>
9<isif condition="${color == '#00FFFF'}">
10<isset name="color" value="${'#00CCFF'}" scope="PAGE">
11<iselseif condition="${color == '#00CCFF'}">
12<isset name="color" value="${'#0099FF'}" scope="PAGE">
13<iselse>
14<isset name="color" value="${'#00FFFF'}">
15</isif>
16</isloop>
17</table>