Specification: isset
isset Element
Define and set a user-defined variable.
Syntax
<isset
name="var_name"
value="${var_value}"
scope="session"
/>
name
Required
Allowed data type: expression or string.
var_name
specifies the name of a user-defined variable. The rules for naming user-defined variables are:
- The identifier must start with a letter (a-z, A-Z).
- Any following character can be a letter, number, or underscore.
- User-defined variables are case-sensitive.
value
Required
var_value
specifies a value to be stored in the variable. It can be any value.
scope
Required
session
variables are available across multiple requests within a session.request
variables are available for the current internal Salesforce B2C Commerce request. Therequest
variable isn't available for multiple requests, so it isn't available after an interaction continue node.page
variables are available for the current ISML page.
The default scope is the session.
The pdict
variable is deprecated. Instead, use the scope="request"
variable. The pdict
variable isn't available for multiple requests, so it isn't available after an interaction continue node.
Purpose
In B2C Commerce, every user-defined variable is of a specific scope, which defines the visibility and lifetime of the variable. B2C Commerce distinguishes between user-defined variables of the request, pdict, session and page scope.
Scope session means that the variable is accessible to all templates during a particular storefront session. The lifetime of a session variable ends with a session. A session variable can be used in expressions.
The first occurrence of <isset>
in a template declares and sets the variable, there is no other special tag needed for declaration. If the variable already exists, <isset>
resets it to the specified value.
Note If no scope is set when setting the variable, the scope is set to session.
Examples: Using Isset to Create a Custom Variable
Example 1
This example shows how <isset>
is used to define and initialize the variable color. The value of color is the string #A0CC99.
<isset name="color" value="${'#A0CC99'}">
Example 2
If a variable was already defined by a former <isset>
tag (first line), a second <isset>
resets the value of the variable (second line).
<isset name="counter" value="${0}" >
<isset name="counter" value="${counter + 1}">
Example 3
In this example <isloop>
is used to get products from the Pipeline Dictionary.
<isloop iterator="${pdict.ProductPagingModel.pageElements}" alias="LoopProduct" begin="0" end="2">
Example 4
This example shows how <isset>
assigns the value of LoopProduct to Product.
<isset name="Product" value="${LoopProduct}" scope="request">
You can also manipulate a value, as shown here:
<isset name="brandsPerCol" value="${Math.floor(numOfBrands/4) + 1}" scope="page">
You can print the value with <isprint>
.
See isremove.
Examples: Accessing Custom Variables
Example 1: Accessing the Page Scope
In this example, isset
sets the decorator template to pt_empty
if the pdict
format attribute is set to ajax and to the pt_account
template if it's not. The DecoratorTemplate variable that is set is accessed by ${DecoratorTemplate}
.
<isset name="DecoratorTemplate" value="account/pt_account" scope="page"/>
<isif condition="${pdict.CurrentHttpParameterMap.format.stringValue == 'ajax' || pdict.CurrentHttpParameterMap.pwr.stringValue == 'true' || pdict.CurrentHttpParameterMap.source.stringValue == 'search' || pdict.CurrentHttpParameterMap.source.stringValue == 'quickview' || pdict.CurrentHttpParameterMap.source.stringValue == 'cart'}">
<isset name="DecoratorTemplate" value="util/pt_empty" scope="page"/>
</isif>
<isdecorate template="${DecoratorTemplate}">