isif Element

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

Syntax

<isif condition = if_expression>
  ...
 <iselseif condition = elseif_expression> //0 or more
  ...
 </iselseif> 
 <iselse>
  ...
</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.

<isif condition="${pdict.Products.Price == 0}"> 
Special free gift.
<iselseif condition="${pdict.Products.Price < 100}">
Special deal.
<iselse>
Today's low price.
</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.

<isset name="color" value="${'#00FFFF'}" scope="PAGE">
<table>
<isloop iterator="${pdict.Basket.products} var="product">
<tr>
<td bgcolor="${product.color}">
<isprint value = "${product.name}">
</td>
</tr>
<isif condition="${color == '#00FFFF'}">
<isset name="color" value="${'#00CCFF'}" scope="PAGE">
<iselseif condition="${color == '#00CCFF'}">
<isset name="color" value="${'#0099FF'}" scope="PAGE">
<iselse>
<isset name="color" value="${'#00FFFF'}">
</isif>
</isloop>
</table>