Templates

In the __cp_response or X-CP-RESPONSE, you can use some template tags to generate dynamic data.

{{ date }}

You can use the {{ date timezone="UTC" format="locale" locale="Europe/Berlin" localePreset="DATETIME_FULL" }} template tag to generate current date. By default, the timezone is UTC and the format is ISO8601. If the format is "locale" string, you can specify the locale with one of the language codes (LCID string, e.g., 'de-CH', 'ja', etc). Then you can specify one of the presets in the localePreset, e.g., DATETIME_FULL shows the full date and time.

Basic Example

The following template will be rendered as current time of UTC time zone in ISO8601 format.

{"result":"{{ date }}"}

Time zone Example

The following template will be rendered as current time in Berlin in ISO8601 format.

{"result":"{{ date timezone='Europe/Berlin' }}"}

Locale Example

The following template will be rendered as current time in UTC in Swiss German locale.

{"result":"{{ date format='locale' locale='de-ch' localePreset='DATETIME_FULL' }}"}

Demo

Codesandbox

repeat(aNumber)

If you're mocking a JSON response, you can use repeat(put_a_number) to dynamically create an array. All you have to do is provide an array with two elements:

  • The first element has to be a string: repeat(2). Replace 2 with the number of elements you want to generate.
  • The second element is the element that will be repeated x number of times, where x is the number you set in the first element.

Array with string elements

Create a JSON array of string elements.

["repeat(3)", "repeated text"]

Array with object elements

Create a JSON array of object elements.

["repeat(3)", {"id":"1"}]

Array in nested property

Create an array of object elements in a property.

{
   "id":"1",
   "children":[
      "repeat(2)",
      {
         "id":"children-id"
      }
   ]
}

Combine with date template

Create a JSON response which contains {{ date }} template.

{
   "id":"1",
   "children":[
      "repeat(2)",
      {
         "current":"{{ date format='locale' locale='ja-jp' }}"
      }
   ]
}