---
title: "ISML"
author: "kirenenko04"
date: "2014-07-27T15:07:27Z"
tags: []
categories: ["编程语言"]
slug: "isml"
draft: false
lastmod: "2014-07-27T15:28:12Z"
id: 2096889
url: "https://kirenenko04.iteye.com/blog/2096889"
---

[]()[]()**Internet Store Markup Language (ISML)**

 

**ISML Templates**

 

Internet Store Markup Language or ISML templates are files with an extension of **.isml** which define how **data**, **tags** and **page markup** are transformed into HTML that is sent to the browser, using CSS for page layout and styling.

 

The Demandware platform uses templates to generate **dynamic** HTML-based Web pages for **responses sent back (****响应发送返回****)** to the client. Templates are created using **Internet Store Markup Language** (ISML) tags and expressions.

 

Describing a Demandware application using **Model-View-Controller** pattern, **templates** =&gt;"**view**", **pipelines** =&gt;"**controller**" and the **DW, Script API** =&gt;"**model**".

 

 

 

**create an ISML template**

 

File -&gt;New ISML Template

 

 

 

**ISML Tags and Expressions**

 

ISML tags are Demandware **proprietary extensions** to HTML that developers use inside ISML templates. ISML tags and expressions cannot be written in any other file other than (除了) ISML templates.

 

ISML tags are SGML-like extension tags that start with **is**, e.g. &lt;isprint&gt; and describe, together with regular HTML, how dynamic data will be **embedded** (嵌入) and **formatted** on the page.

 

 

 

**ISML tags can be divided into the following groups**

 

**HTTP-related :**

 

1. **&lt;iscookie&gt;**
   
   Sets cookies in the browser
2. **&lt;iscontent&gt;**
   
   Sets the MIME type
3. **&lt;isredirect&gt;**
   
   Redirects browsers to specific URLs
4. **&lt;isstatus&gt;**
   
   Define status codes

 

**Flow Control :**

 

1. **&lt;isif&gt;**
   
   Evaluates a condition
2. **&lt;iselse&gt; &lt;iselseif&gt;**
   
   Specifying alternative logic
3. when an **&lt;isif&gt;** condition does
   
   not evaluate to true.
4. **&lt;isloop&gt;**
   
   Creates a loop statement
5. **&lt;isnext&gt;**
   
   Jumps to the next iteration in a
   
   loop statement
6. **&lt;isbreak&gt;**
   
   Terminates loops

 

**Variable-related :**

 

1. **&lt;isset&gt;**
   
   Creates a variable
2. **&lt;isremove&gt;**
   
   Removes a variable

 

**Include :**

 

1. **&lt;isinclude&gt;**
   
   Includes the contents of one template on the current template
2. **&lt;ismodule&gt;**
   
   Declares a **custom tag**
3. **&lt;iscomponent&gt;**
   
   Includes the **output of** a pipeline on the current page

 

**Scripting :**

 

1. **&lt;isscript&gt;**
   
   Allows Demandware Script execution inside templates

 

**Forms :**

 

1. **&lt;isselect&gt;**
   
   Enhances(增强)  the HTML &lt;select&gt; tag

 

**Output :**

 

1. **&lt;isprint&gt;**
   
   **Formats** and **encodes** strings for output
2. **&lt;isslot&gt;**
   
   Creates a **content slot**

 

**Others:**

 

1. **&lt;iscache&gt;**
   
   Caches a page
2. **&lt;iscomment&gt;**
   
   Adds comments
3. **&lt;isdecorate&gt;**
   
   Reuses a template for page layout
4. **&lt;isreplace&gt;**
   
   Replaces content inside a decorator template

 

**Active Data :**

 

1. **&lt;isactivedatahead&gt;**
   
   Allows collection of active data from pages with a **&lt;head&gt;** tag
2. **&lt;isactivecontenthead&gt;**
   
   Collects **category** context from a page for active data collection
3. **&lt;isobject&gt;**
   
   Collects **specific object** impressions/views dynamically

 

 

 

**ISML Expressions**

 

**ISML Expressions** are **based on** the Demandware Script language. Since Demandware Script implements the **ECMAScript** standard, access to variables, methods and objects is the same as using JavaScript.

 

ISML expressions are embedded inside **${…}** to allow the ISML processor to interpret (解释) the expression prior to(优先于) executing an ISML tag or the rest of the page. ISML expressions provide **access** to **data** by using **dot notation**. Here is an example of accessing a property of the Product object in the pipeline dictionary:

 

**${pdict.Product.UUID}**

 

The difference between this **ISML expression** and one used inside a pipeline node property (i.e. decision node) is that **in ISML** you ***must*** specify the **${pdict.object.property}** if you want to access a value in the pipeline dictionary, whereas **inside pipeline node properties** the access to the pdict is implicit(隐式) and the ${} ***not used*** : i.e. Product.UUID

 

ISML expressions can also **access Demandware Script** classes and methods. **Some** **packages** are **available** **implicitly**, so classes do not need to be fully qualified:

 

1\. **TopLevel** package: session. getCustomer()

 

2\. **dw.web** package: URLUtils.url(), URLUtils.webRoot()

 

**Other** access to classes and methods **must be fully** qualified:

 

**dw.system.Site.getCurrent()**

 

ISML expressions can also allow **complex arithmetical** (复合算数), boolean and string operations:

 

**${pdict.Product.getLongDescription() != null}**

 

 

 

**IMPORTANT NOTE**

 

Although there are some ISML tags that do not need a corresponding (相应的)  closing &lt;/&gt; tag (i.e.: the &lt;isslot&gt; tag), it is **best practice** to **always** use a closing tag.

 

 

 

**Creating and Accessing Variables: &lt;isset&gt;**

 

You can create and access your own **custom variables** in an ISML template by using the **&lt;isset&gt;** tag (to create and access variables **in Demandware Script**)

 

When using the &lt;isset&gt; tag, the **required attributes** that must be assigned are **name** and **value**. The *default scope* is **session**, so you must be careful to qualify your variables accordingly if you do not want them.

 

Example:

 

    **&lt;isset**

 

        **name** = "&lt;name&gt;"

 

        **value** = "&lt;expression&gt;"

 

        **scope** = "session"|"request"|"page"

 

    **&gt;**

 

The **value** attribute can be either a **hardcoded** string or number or an ISML **expression** accessing another variable or object:

 

**string:**  value=”hardcoded text”

 

**expression:**  value=”${pdict.Product.name}”

 

The scope attribute of a variable refers to the level of accessibility of the variable. The **three** available levels to you as a **developer** are **session**, **request**, and **page**.

 

 

 

**Variable Scope**

 

Demandware offers the following scopes, listed here from *widest to narrowest* access (从大到小). It is **important** to understand the different scopes of a variable and what objects can access a variable at each level.

 

- **Global** Preferences:
  
  accessible via the **dw.system.OrganizationPreferences** class. Available to **any site within an** **organization**.
- **Site** Preferences:
  
  accessible via the **dw.system.SitePreferences** class. Available to any pipeline executing **as part of a site**.
- **session**:
  
  available through the **whole** **session**.
- **pdict**:
  
  available while a **pipeline executes**. It might encompass (包含) multiple requests, like when using **Interaction Continue Nodes**
- **request**: available through a **request-response** cycle. Typically the **same as the pipeline** scope.
- **page:** available only for a **specific page**, and **its locally** (本地的) included pages.
- **slotcontent**: available only in the rendering template for a content slot.
- **&lt;isloop&gt; variable**: available only **inside** the **loop**.
  
   
  
  **Session variables** are available across **multiple requests** within a customer session. Any variable added to the session scope becomes a **custom attribute** of the **session object**. Since it is not a standard attribute it **must be** accessed with the **session.custom** qualifier:
  
  **${session.custom.myVar}**
  
   
  
  **Request variables** are available via the request scope. A request variable is available only for a **single** browser **request-response cycle**: it does *not* persist in memory for a subsequent(后来的) request. Similar to session variables, you must prefix request variables with a qualifier **request.custom** when accessing them:
  
  **${request.custom.myRequestVar}**
  
   
  
  **Page variables** are available on the **current** ISML page, and their scope is limited tothe current template, and any **locally** **included** templates.They are accessed without a prefix:
  
  **${pageVar}**
  
   
  
  **Setting and retrieving variables**

 

1. In the template, create a new variable called **sessionVar** with **hardcoded** textas the value and print the value to the page:
   
   &lt;isset name="sessionVar" value="${1}" scope = "session"/&gt;
2. The value of the sessionVar variable is:
   
   ${session.custom.sessionVar}&lt;br/&gt;
3. **Increment** the variables by using syntax like
   
   value="${request.custom.requestVar + 1}"
   
    
   
   **Reusing Code in Templates**
   
   There are **four** **tags** available to you as a developer for **reusing code** in ISML templates**:**

 

1. **&lt;isinclude&gt;** **包含标签**
2. **&lt;isdecorate&gt;** **装饰标签**
3. **&lt;ismodule&gt;** **自定义标签**
4. **&lt;iscomponent&gt;** **组件标签**
   
    
   
   **Reusable code for these purposes:**

 

- Saves time 节约时间
- Reduces the likelihood of errors 减少可能的错误
- Minimizes the chore of updating pages 最小化更新页面的工作
- Helps to ensure a consistent look and feel 帮助确保一致性
  
   
  
  **The &lt;isinclude&gt; Tag** **包含标签**
  
  The &lt;isinclude&gt; tag allows you to **embed** an **ISML template** inside the **invoking** template. There are two types of includes:

 

- **Local Include** (本地包含) – allows you to include the code of one ISML template *inside of another while generating the page*
- **Remote Include** (远程包含) – allows you to include the **output of another pipeline** inside of an ISML template. The primary purpose for using a remote include is for **partial page caching**.
  
   
  
  **Local Includes** **本地包含**
  
  Local includes are **heavily** used throughout SiteGenesis.
  
  The **syntax** for using a **local include** is:
  
  &lt;isinclude template="\[directory/]templatename" /&gt;
  
  You do **not** need to add the **'.isml'** extension when including a template.
  
   
  
  **Local Includes Example**
  
  **Template 1:**
  
  &lt;h1&gt;My Template&lt;/h1&gt; &lt;br/&gt;
  
  &lt;isinclude template="extras/calendar" /&gt;
  
  **Template 2 (calendar.isml)**
  
  &lt;h1&gt;Included template&lt;/h1&gt;
  
   
  
  **IMPORTANT NOTE**
  
  **1. Local Include** - **All** variables from the including template are **available** in the included template, including **page** variables.
  
  **2.****Remote Include** -Pdict and page variables from invoking template are **NOT** available in the included template. The **only** variables
  
  available to a remotely included pipeline are **session variables**.
  
  3\. Includes **from another server** are **not** supported.
  
   
  
  **Remote Includes**
  
  The **syntax** for a remote include is
  
  &lt;isinclude url="pipeline\_url" /&gt;
  
  Using a remote include in a template will invoke **another pipeline** which **returns HTML** at runtime. The examples below show how to call a pipeline without passing URL parameters:
  
  &lt;isinclude url="${URLUtils.url('Product-IncludeLastVisited')}" /&gt;
  
  In the example above, the **dw.web.URLUtils url()** method builds a **site-specific** URL for the **Product-IncludeLastVisited** pipeline. This is a best practice sinceyou should never **hardcode** a pipeline URL since it would contain a specific serverin it: use **URLUtils** methods instead.
  
  Here is an example of passing URL parameters:
  
  &lt;isinclude url="${URLUtils.url('BrowseCatalog-Hotdeals', 'catalogCategoryID',  'Storefront')}"/&gt;
  
  The page generated by the invoked pipeline can be **dynamic** or it may come from **cache**.
  
  There is a **new** **tag** that implements a **remote include: (****组件标签****)**
  
  **&lt;iscomponent**
  
  pipeline = &lt;string&gt; | &lt;expression&gt;
  
  \[locale = &lt;string&gt; | &lt;expression&gt; ]
  
  \[any number of additional arbitrarily named parameters]
  
  **/&gt;**
  
  This tag allows you to **pass** as **many attributes** as you want **without** having to use the URLUtils methods:
  
  &lt;iscomponent pipeline ="Product-Show" productid="1234" name="Wide-screen television"/&gt;
  
   
  
  **Reusing Code in Templates : &lt;isdecorate&gt; Tag**
  
  The **&lt;isdecorate&gt;** tag lets you **decorate** the enclosed content with thecontents of the specified (**decorator**) template. A decorator is an ISML template thathas **html**, **css**, and **overall design** of a page. The *decorator template* has the tag **&lt;isreplace/&gt;** identifying where the decorated content shall be included.
  
  Typically, **only one** tag (&lt;isreplace/&gt;) is used in the decorator template. However, multiple tags **can** also be used. If the decorator template has **multiple** &lt;isreplace/&gt; tags, the content to be decorated will be included **for each** &lt;isreplace/&gt; tag.
  
   
  
  A typical use case is to decorate the content body with a header and footer:
  
  *Template using a decorator :*
  
  &lt;**isdecorate** template="\[Decorator template name]"&gt;
  
  ...My content...
  
  &lt;/**isdecorate**&gt;
  
  *Decorator template :*
  
      &lt;html&gt;
  
      &lt;head&gt;…&lt;/head&gt;
  
      &lt;body&gt;
  
         &lt;**isreplace**/&gt;
  
     &lt;/body&gt;
  
  &lt;html&gt;
  
  **Run the use &lt;isdecorate&gt; tag activity**
  
  **1.**Open the ISML template that has the code you wish to replace in a decorator. Add the *&lt;isdecorate&gt;* tag around the code you wish to include in a decorator.
  
  &lt;isdecorate template="\[directory/]decoratorname"&gt;
  
  Your code goes here.
  
  &lt;/isdecorate&gt;
  
  **2.** Open the decorator template. If you are using a SiteGenesis template, the decorator templates names start with "pt\_".
  
  **3.** Find the location in the code where you want to use the &lt;isreplace/&gt; tag. Add the tag to the template.
  
   
  
  **Creating Custom Tags with &lt;ismodule&gt;**
  
  The **&lt;ismodule&gt;** tag allows you to **define your own ISML tags**.
  
  There are **three** key **isml files** required for **creating** and **using** a custom tag:
  
  **1**. The isml file which **sets the values of *any* attributes** of the custom tag. See the example below in util/modules.isml
  
  自定义标签属性定义文件
  
  &lt;ismodule template="components/breadcrumbs"
  
  name="breadcrumbs"
  
  attribute="bctext1"
  
  attribute="bcurl1"
  
  attribute="bctext2"
  
  attribute="bcurl2"
  
  attribute="bctext3"
  
  attribute="bcurl3"
  
  /&gt;
  
  **2**. The isml file which **specifies what happens** when the **attributes** are **passed**. See the code snippet from inside breadcrumbs.isml
  
  定义自定义标签展现方式
  
  &lt;isif condition="${pdict.bcurl1 != null}"&gt;
  
  &lt;a href="${pdict.bcurl1}" title="${pdict.bctext1}"&gt;
  
  ${pdict.bctext1}&lt;/a&gt;
  
  &lt;/isif&gt;
  
  **3**. Lastly, you need to **invoke** the **custom tag** inside an isml template:
  
  调用自定义标签
  
  &lt;html …&gt;
  
  &lt;isinclude template="util/modules"/&gt;
  
  &lt;head&gt;…&lt;/head&gt;
  
  &lt;body&gt;
  
      …
  
      &lt;**isbreadcrumbs** bctext1="…" bcurl1="…"/&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  
   
  
  **Conditional Statements and Loops**
  
  syntax:adds "**is**" to the beginning of tags
  
  &lt;**isif** condition=”${ISML expression evaluated}”&gt;
  
  Do something here if true.
  
  &lt;**iselseif** condition=”${check another condition}”&gt;
  
  Do something if this one is true.
  
  &lt;**iselse**&gt;
  
  If none of the above conditions are true, do this.
  
  &lt;/**isif**&gt;
  
   
  
  **Loops**
  
  With **&lt;isloop&gt;** you can loop through the elements of a specified **collection** or **array**. As an example, you can list data like categories, products, shipping and payment methods. An &lt;isloop&gt; statement **can be nested** in one another.
  
   
  
  **Supporting tags**
  
  **&lt;isbreak&gt;** : can be used within a loop (defined by an &lt;isloop&gt; tag) to **terminate** a loop unconditionally. If &lt;isbreak&gt; is used in a nested loop, itterminates only the **inner** loop.
  
  **&lt;isnext&gt;**: to jump forward in a loop. Jumping **forward** within a loop to the **next** list **element** of an iterator. This tag affects only the iterator of the **inner** loop. The **syntax** for using the **&lt;isloop&gt; tag** is:
  
  &lt;isloop
  
  iterator|items = "&lt;expression&gt;"
  
  \[ alias|var = "&lt;var name&gt;" ]
  
  \[ status = "&lt;var name&gt;" ]
  
  \[ begin = "&lt;expression&gt;" ]
  
  \[ end = "&lt;expression&gt;" ]
  
  \[ step = "&lt;expression&gt;" ]
  
  &gt; 
  
  …do something in the loop using &lt;var\_name&gt;…
  
  &lt;/isloop&gt;
  
  *The attributes have the following usage:*

 

- items (iterator)
  
  Expression returning an object to iterate over. Attributes iterator and
  
  items can be used interchangeably (可交换的) .
- var (alias)
  
  Name of the variable referencing the object in the iterative collection
  
  referenced in the current iteration.
- status
  
  Name of the variable name referencing **loop status** object. The loop
  
  status is used to query information such as the counter or whether it is
  
  the first item.
- begin
  
  Expression specifying a begin index for the loop. If the begin is greater
  
  than 0, the &lt;isloop&gt; skips the first x items and starts looping at the
  
  begin index. If begin is smaller than 0, the &lt;isloop&gt; is skipped.
- end
  
  Expression specifying an end index (inclusive). If end is smaller than
  
  begin, the &lt;isloop&gt; is skipped.
- step
  
  Expression specifying the step used to increase the index. If step is
  
  smaller than 1, 1 is used as the step value.
  
   
  
  *For the status variable, the following properties are accessible:*
- count
  
  The number of iterations, starting with 1.
- index
  
  The current index into the set of items, while iterating.
- first
  
  True, if this is the first item while iterating (count == 1).
- last
  
  True, if this is the last item while iterating.
- odd
  
  True, if count is an odd value.
- even
  
  True, if count is an even value.
  
  For example, if the &lt;isloop&gt; tag declares a **status=”loopstate”** variable, then it is possible to determine the first time the loop executes by using: &lt;isif condition="**loopstate.first**" &gt;
  
   
  
  **Using Loops**
  
  **1.**Implement the following code to display the products in the cart
  
  &lt;isloop
  
  items="${pdict.Basket.allProductLineItems}"
  
  var="productLineItem"&gt;
  
  ${productLineItem.product.name}&lt;br/&gt;
  
  &lt;/isloop&gt;
  
  2.Replace the allProductLineItems property of the basket with the method getProductLineItems().