Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Developing with Sitecore Personalize
Data privacy
Before you start sending data
Integrating with Sitecore Personalize
Stream API
Personalize API Flow execution
REST APIs
  • Sitecore Personalize for developers
  • REST APIs
  • Template REST API
  • Preview template code

Preview template code

POST /v3/templates/process

This endpoint lets you test template code that contains template parameters. Template parameters are dynamic placeholders that are replaced with template variable values when the template is rendered.

In the request, you include both the template parameters and the template variable values. In the response, the entire template code is returned, containing the template variable values.

At a minimum, you must provide the following required attributes in the request body:

Attribute

Type

Description

Example(s)

templates

JSON array of JSON objects

Custom HTML, CSS, JavaScript, and FreeMarker codes that define the template.

N/A

templateVariables

object

Template variables and their corresponding values.

{ "Name": "John", "ProductType": "sneakers" }

For the objects in the templates array of objects, use the following attributes:

Attribute

Type

Description

Example(s)

id

string enum (lowercase)

The type of code that you include in the template attribute.

For example, to include CSS code in the template, set this value to "css", then specify the custom CSS code in the template attribute.

Must be one of:

  • "html"

  • "css"

  • "js"

  • "freemarker"

template

string

Stringified HTML, CSS, JavaScript, or FreeMarker code.

For FreeMarker code, you must at a minimum include an opening and a closing curly bracket {}.

  • HTML: "<div id=\"test\">Our best [[ProductType | string]] on sale</div>"

  • CSS: "#test {text-transform: uppercase}"

  • JavaScript: "insertHTMLBefore(\"body\");"

  • FreeMarker: "{}"

In the request, you include template parameters, for example, [[ProductType | string]] and template variable values, for example, sneakers for ProductType:

RequestResponse
curl -X POST '<baseURL>/v3/templates/process' \
-H 'Authorization: Bearer <accessToken>' \
-H 'Accept: application/json' \
--data-raw '
{
  "templates": [
    {
      "id": "html",
      "template": "<title>Hi, [[Name | string]]!</title>\n<content>This week, our [[ProductType | string]] are on sale!<content>"
    },
    {
        "id": "css",
        "template": "title {text-transform: [[Style | string]]}"
    }
  ],
  "templateVariables": {
    "Name": "John",
    "ProductType": "sneakers",
    "Style": "uppercase"
  }
}'

In the response, the entire template code is returned containing the template variable values, for example, John, sneakers, and uppercase:

RequestResponse
{
    "templates": [
        {
            "id": "html",
            "template": "<title>Hi, John!</title>\n<content>This week, our sneakers are on sale!<content>"
        },
        {
            "id": "css",
            "template": "title {text-transform: uppercase}"
        }
    ]
}

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2025 Sitecore