Cert++
Close

ISML expressions and conditional rendering with isif

Key Takeaway

Guard dynamic output with <isif> and print it with <isprint>, which HTML-encodes by default. A bare ${...} expression is not encoded in an included template that sets no content type.

ISML templates mix regular HTML with B2C Commerce tags whose names start with "is" and with expressions written as ${...}. Expressions pull dynamic data into the page, mostly from the Pipeline Dictionary (pdict). The <isif> tag group shows or hides parts of the page based on a condition. The way you print a value decides whether it is HTML-encoded. Encoding matters because unencoded data can expose the page to cross-site scripting (XSS).

ISML tags and expressions

ISML tags are commands inside a template. They control how B2C Commerce embeds live data into a page and how that data is formatted with the regular HTML. Every tag name starts with "is", such as <isprint>, <isset> or <isif>. Tag names and attribute names are not case sensitive, but attribute values often are. A string compared inside a condition must therefore match exactly. Salesforce recommends writing tags in lower-case.

An ISML expression has the syntax ${...}, and everything between ${ and } is evaluated as an expression. Its syntax and meaning are based on JavaScript and are similar to JSP expressions.

An expression can sit directly in the template markup or inside a tag attribute. Use expressions only where a tag explicitly allows them, because an expression in a place that doesn't allow one causes an exception.

<isprint value="${pdict.Product.name}">
<form action="${URLUtils.continueURL()}" method="post">

The first line prints a product name. The second line builds a form URL.

Any data a template displays must be available in the Pipeline Dictionary. Expressions read that data through pdict, as in ${pdict.Product}, ${pdict.ProductPrices} and ${pdict.Order.orderNo}. Expressions can also call methods, as in ${pdict.Product.getLongDescription() != null}.

Expressions are not the only way to add logic to a template. For larger blocks of logic, write a scriptlet inside <isscript> instead.

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. 796 members and growing.