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.
The following template will be rendered as current time of UTC time zone in ISO8601 format.
{"result":"{{ date }}"}
The following template will be rendered as current time in Berlin in ISO8601 format.
{"result":"{{ date timezone='Europe/Berlin' }}"}
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' }}"}
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:
repeat(2)
. Replace 2
with the number of elements you want to generate.Create a JSON array of string
elements.
["repeat(3)", "repeated text"]
Create a JSON array of object
elements.
["repeat(3)", {"id":"1"}]
Create an array of object
elements in a property.
{ "id":"1", "children":[ "repeat(2)", { "id":"children-id" } ] }
Create a JSON response which contains {{ date }}
template.
{ "id":"1", "children":[ "repeat(2)", { "current":"{{ date format='locale' locale='ja-jp' }}" } ] }