Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Content Wrapper XML file

Content Wrapper XML file


This setting specifies the name of the Content Wrapper template file that contains the template code used to render the Content Wrapper.


The CWT file must be located in the same directory as the Content Wrapper.


The ID is used internally by Elastic Path Commerce to identify the Content Wrapper. Each Content Wrapper must have a unique ID. If there are multiple Content Wrappers with the same ID, only one of them will be loaded.


The name is the human-readable name displayed to the user in the Commerce Manager.


Currently, only groovy is supported.


(Optional.) The service definitions block is used to add references to Elastic Path service beans. If the script code in the Content Wrapper needs to refer to Elastic Path services, add references to the service beans here.


A references to an Elastic Path service bean. The name attribute specifies the name you want to use within the Content Wrapper to refer to the service. For example, the following adds a reference to the productService bean:

<service-definition name="myProductService">productService</service-definition>

To refer to this bean within the Content Wrapper, you would use the name myProductService.


(Optional.) The user input settings block contains parameters that the marketing user configures when creating Dynamic Content.


A parameter that the marketing user configures when creating Dynamic Content.

<user-input-setting id="productCode"
    name="Product Code"
  • id is the name that can be used to refer to the setting in the <init> block and all <template-parameter> blocks.
  • name is the text displayed to the user in the Commerce Manager when configuring the Dynamic Content.
  • required sets whether this is a mandatory setting (i.e., the Commerce Manager user must configure it when creating Dynamic Content with this Content Wrapper).
  • pass-to-template sets whether the setting can be accessed from the Content Wrapper template file. By default, the setting is passed as a parameter to the template. To prevent this, set pass-to-template to false. Also note that all settings passed to the template are automatically required, regardless of the required attribute.
  • localizable indicates whether the value can have different values for different locales. If it is set to true, the person configuring the Dynamic Content can specify a different value for each supported language.
  • type determines what kind of values it supports. The following type values are supported:
    Type Comments


    Displays a multiline text box.


    Displays a text box.


    Displays a special list edit that allows the user to specify multiple string values.


    The user can select either true or false.


    The user can specify a numeric value containing non-whole (or fractional) numbers.


    The user can specify a numeric value containing whole numbers.


    Displays a file dialog that prompts the user to select an image in the <assets>/dynamiccontent directory.


    Displays a file dialog that prompts the user to select a file in the <assets>/dynamiccontent directory.


    Prompts the user to select a date using a date picker.


    Prompts the user to select a date using a date picker.


    User input is validated to ensure that a proper URL is set. Only http, https, and ftp protocols are supported.


    Displays a product search dialog.


    Displays a category search dialog.


    The user can specify a string of HTML in a multi-line text box.


The initialization block lets you add initialization logic to the Content Wrapper. This code is executed each time the Content Wrapper is loaded. For more information, see Writing Code in Content Wrappers.


(Optional.) Additional parameters that are available in the Content Wrapper template file.


An additional parameter that is available in the CWT.

<template-parameter id="image" name="image">

You can include business logic to resolve the parameter values. The code inside each template parameter element must return the value that will be passed to the CWT. The value must not be null.


The return keyword is optional. If there is no return, the value returned by the last line of code is used as the return value.

Writing Code in Content Wrappers

The <init> block in the Content Wrapper XML file lets you add initialization logic to the Content Wrapper. You can also include code in the <template-parameter> blocks. The code in these blocks is executed each time the Content Wrapper is loaded.

Because the code is embedded in XML, you need to wrap it in a CDATA block to ensure XML special characters in your code are not interpreted by the XML parser. Alternatively, you can manually escape special characters (converting < to <, & to &, etc.).

// Groovy code here
]] >

Importing packages

By default, all Java packages and all packages in the storefront web application's classpath are imported automatically. It is not necessary to import them explicitly.

Variable scope

It's important to note that if you declare a variable with def, its scope is local to the current block. Thus, if you create a variable in the init block and you want to access it inside a template-parameter block, do not declare it with the def keyword. You only need to assign it a value.

Available objects

In addition to any variables you declare, the following objects are available in your script code:

  • CS: a CustomerSession object representing the shopper
  • locale: a string containing the current locale