Cert++
Close

User-defined variables and scopes with isset and isremove

Key Takeaway

If you leave out the scope attribute on <isset>, the variable goes into session scope. Every template can then see it on later pages and requests for the rest of the storefront session.

ISML templates can store their own values in user-defined variables. You create or change a variable with <isset> and delete it with <isremove>. Each variable has a scope of page, request or session. The scope sets where the variable can be seen and how long it lives. A variable in the wrong scope can be missing where you need it, or still be set where you don't expect it.

Creating and resetting a variable with isset

<isset name="var_name" value="var_value" scope="..."/> sets a user-defined variable. The first <isset> for a name both declares and sets the variable, so ISML has no separate declaration tag. A later <isset> with the same name resets the variable to the new value.

The name attribute accepts either a string or an expression. The value attribute can hold any value, including an expression that does math or uses other variables. For example, value="${Math.floor(numOfBrands/4) + 1}" stores a calculated number. Inside an <isloop>, value="${LoopProduct}" copies the current loop item into a new variable.

A reset can use the variable's old value, as in this counter:

<isset name="counter" value="${0}">
<isset name="counter" value="${counter + 1}">
<!-- counter is now 1 -->

The first tag sets counter to 0. The second tag resets the existing variable, and its expression reads the old value and adds 1. As a result, counter equals 1.

To read a variable, use its name in an expression, such as ${counter}. To output its value, use <isprint>. You can put <isset> anywhere in a template.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Given a development task, code ISML templates that use functionality, such as local include, remote include, components, and other ISML tags

0/14

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers.