Template code is SFCC JavaScript with the Script API behind it. pdict gets its members from what controllers pass, and template variables carry their types
pdict has the members the controller passes to res.render. Completion lists them with their types, and the documentation beside the list says which line sets each oneWhere JavaScript lives
| Where | Example |
|---|---|
${...} in text and attribute values | ${product.productName} |
The body of <isscript> | var assets = require('*/cartridge/scripts/assets'); |
| Expression attributes | condition, value, items, iterator, begin, end, step |
${...} in a <script> block, also between backticks | var brand = '${product.brand}'; |
The IDE's JavaScript features work there: completion, Go to Declaration, Find Usages, parameter info and parameter name hints. The scope is the B2C Script API with its standard library, the SFRA server module and the template, so document doesn't resolve. A client-side <script> block keeps the browser scope
${ and } use the string escape color by default, set in Settings › Editor › Color Scheme › ISML › Expressions › ${ } delimiters
Names in every template:
| Name | Type |
|---|---|
pdict | The pipeline dictionary, typed from the render calls |
Resource | dw.web.Resource |
URLUtils | dw.web.URLUtils |
StringUtils | dw.util.StringUtils |
out | dw.io.PrintWriter |
Browser scripts
B2C runs every ${} of a <script> block on the server before the browser sees the script, even inside a JavaScript template literal. Each one gets a blue note that explains what the printed value turns into, see Server-side expressions in scripts. For a template literal placeholder the browser fills, write ${'$'}{name}, which B2C prints as ${name}
${} between backticks with a name the template does not define was meant for the browser, but B2C evaluates it first. The fix writes it as ${'$'}{points}: B2C prints the $, and the browser gets ${points} to fillpdict
pdict gets its members from three places, in this order:
@pdict lines
@pdict {Type} name description lines in a template comment. They win over everything else, see @pdict declarations
Render calls
The model passed by every controller, script and pipeline that renders this copy of the template: res.render, ISML.renderTemplate, app.getView().render and new dw.util.Template().render. res.render('account/loyalty', { points: points }) adds pdict.points with the type of points. A conditional path, such as res.render(isGuest ? 'checkout/guest' : 'checkout/login', model), types both templates
A locale copy, such as templates/ja_JP/account/loyalty.isml, gets the pdict of what renders its path, account/loyalty, so it completes like the default copy
PipelineDictionary
Members of dw.system.PipelineDictionary set for every template, such as CurrentCustomer and CurrentSession
In SFRA the plugin also reads res.setViewData and res.getViewData across the route's handlers, server.append and server.prepend in other cartridges and the route's middleware, up to 50 functions deep. Page Designer component models count too. Members of a render call that builds its template path at run time are optional. A render call still adds every member it names when the rest of its model is unknown: a route with middleware the plugin can't follow, a model with a spread, or a model passed to a helper
An open template follows the editor text of the controller, form or resource bundle that sets its pdict, so completion, member types and the unknown member warning change as you type there, before you save
A member that only some render calls set is optional. Quick documentation (F1, Ctrl+Q) on a member says which line sets it:
| Section | Shows |
|---|---|
| Title | pdict.points: number and the kind, pipeline dictionary member |
| Set by: | Each assignment with its file and line, for example points: loyaltyHelpers.getPoints(customer) in app_custom/cartridge/controllers/Loyalty.js, line 5 |
| Optional: | How many render calls set it, for example "set by 2 of 3 sources" |
| Declared: | The @pdict line, when a template header declares the member |
When several render calls set a member, its type is the union of what they pass, and Ctrl+Click (Cmd+Click on macOS) lists each of them to pick from
On pdict itself it lists the members, and says other members may exist when a render call is unknown or passes a computed model
pdict flows through includes, decorators and custom tags. A custom tag's attributes arrive in its template as pdict.<attribute>, in lower case
Pipelines
A template that a pipeline renders with an Interaction node or the SendMail pipelet gets the keys the pipeline puts on the way there
Basket output of GetBasket, typed from the pipelet. Cmd+Click opens the Pipeline Editor on the node with the key selected| Node | Puts |
|---|---|
| Assign | The key each To_n binds |
| Eval | The key Result binds |
| System pipelet | The keys its outputs bind, typed from the pipelet, such as dw.web.PagingModel from Paging |
| Loop | The element-key |
| Script | The keys bound to outputs the script declares with @output, with their type |
The keys of the pipelines it calls with Call nodes count too, and a start that other pipelines call or jump to sees what each caller puts before the call. Cmd+Click on such a member opens the pipeline at the node that puts the key. Keys from Assign, Eval and Loop nodes are any
Template variables
<isset name="basket" value="${dw.order.BasketMgr.getCurrentBasket()}" scope="page" />
${basket.totalGrossPrice}<isset name> declares a variable with the type of its value. A later <isset> with the same name sets it again
The innermost loop variable wins, then the nearest declaration before the use, in this template or in one it included before the use
Each <isset> and <isloop> variable shows its type as a hint, such as : dw.order.ProductLineItem (ISML variable types in Settings › Editor › Inlay Hints). Quick documentation on a variable shows its declaration, its scope and, for a loop status, the members
Across templates
A template rendered in place reads the variables of the template that renders it, as the server runs them
<isset> and loop variables set before its <isinclude>. Completion names the template that declares each one, and Cmd+Click opens the declaration there| Rendered by | Sees |
|---|---|
<isinclude template> or a custom tag | The variables set before it and the loop variables around it, so lineItem and loop of the <isloop> it sits in |
<isdecorate> | Every variable of the decorated template |
<isinclude url> | Nothing, it's a request of its own |
- The template that includes another sees what the included template sets, after the include
- An
<isset>without a scope is asessionvariable, which any template can read <isset scope="request">andscope="pdict"put the name in the pipeline dictionary, sopdict.namereads it in the templates that follow- Completion names where each variable comes from, such as
isset in cart.isml,isset session in header.isml,isloop in cart.ismlorisloop status in cart.isml, withsessionvariables last - A variable that several templates set, such as each copy of a checkout template, has the union of their types, and
Cmd+Clicklists each<isset> Cmd+Click, Find Usages and Rename follow the variable into the other templates, and an edit in one template updates the others at once
Overridden copies
A template copy that nothing includes and nothing renders, such as an integration cartridge's checkout/customer/customerCard.isml that the site cartridge overrides, sees the variables that the templates including its path set. So ${sitePreferences.amzPayEnabled} in that copy is typed, completes and opens its <isset>, as in the copy B2C Commerce renders. A copy that something includes or renders sees exactly its own includers
sitePreferences is typed there as in the copy in use, and Cmd+Click opens its <isset>Variables from other templates need a license or trial and wait for indexing to finish
Forms and custom attributes
| In a template | Typed from |
|---|---|
pdict.CurrentForms.newsletter.contact.email | The form XML, see Forms |
A form passed to res.render, such as pdict.addressForm | The same form, SFRA or dw.web |
name="dwfrm_newsletter_contact_email" | Completes, opens the field and renames with it |
${dw.system.Site.current.preferences.custom.loyaltyEnabled}, ${product.custom.badgeText} | The metadata XML, see Custom Attributes |
An <isset> variable that holds a form or custom attributes keeps their type in every template that sees it
References and usages
Cmd+Alt+F7) on a script export lists the templates that read it next to the scripts and controllers. A template counts once its <isscript> requires the module, in the script body and in every ${} after itNames in template code are references, as in any script:
| Action | In a template |
|---|---|
Cmd+Click (Ctrl+Click) or Go to Declaration (Cmd+B, Ctrl+B) | Opens the declaration: a top-level var or function of an <isscript>, an <isset name>, or an <isloop> var or status. On a member of a required module, opens the export |
| Usage highlighting | The caret on a name marks its declaration and every read |
Find Usages (Alt+F7) and Show Usages (Cmd+Alt+F7, Ctrl+Alt+F7) | From the declaration or any use, lists every read. Template variables are searched in the templates that can see them, see Across templates |
Rename (Shift+F6) | On an <isset> or <isloop> variable, renames the attribute and every read |
From scripts to templates
A template that requires a module in <isscript> uses its exports like any script. Find Usages and Show Usages on an export, such as ACTION_TYPES in constants.js, list the <isscript> lines and ${...} expressions that read it next to the scripts and controllers
@pdict declarations
A template that no controller renders, such as an email or a content asset template, can declare its members in its first <iscomment>:
<iscomment>
@pdict {dw.customer.Customer} customer The customer who joined
@pdict {number} points Welcome bonus points
@pdict {string} [title] The heading
</iscomment>
<h1>${pdict.title || Resource.msg('mail.welcome.title', 'loyalty', null)}</h1>Brackets mark an optional member. Descriptions show in completion and quick documentation. Custom tag templates write @param lines the same way, see Custom Tags. The Declare 'pdict.x' with @pdict quick fix writes the line, see Inspections
Script compatibility mode
Set Settings › Languages & Frameworks › Digital Script › Script compatibility mode to the mode in Business Manager › Administration › Site Development › Code Deployment, and the Script syntax the compatibility mode does not support inspection reports syntax your instance can't run. One mode covers templates, .ds and server .js files. The ISML page shows it read-only
| Mode | Adds |
|---|---|
| 21.2 | Arrow functions, for...of, generators, shorthand methods, object destructuring |
| 22.7 | Shorthand properties, template literals, exponentiation, BigInt |
No mode supports classes, default parameters, rest and spread, optional chaining, nullish coalescing or async functions. Not set uses the mode of the code version you activate from the B2C explorer, and until then reports only the syntax that no mode supports, see Compatibility mode