Book Documentation Cap Tutorials

1202 script

In model blocks, you can use special scripting to manipulate data. This '1202 script' has a unique syntax and command set.

To make 1202 script easy to learn and understand, it resembles the PHP language, which is one of the most popular languages on the web.


1202 script commands always start with a dollar sign followed directly by the name of the command, for instance the 'trim' command:


A command is always followed by one or more sets of square brackets or 'arguments':

$trim[ some text ]

In this case, the text between the square brackets is the value that should be trimmed. The result will be the removal of leading and trailing spaces.

Note: The number of arguments is different for each command. You have to define all arguments for the command to work.

In some cases, you'll want to define an empty value for an argument. For instance, the 'date' command is defined as:


The first argument is the input value, the second one specifies how the result should be formatted. If you do not supply an 'input', the command will use today's date (this is an example where 1202 script works like PHP):

$date[][%Y-%m-%d] // returns today's date formatted as yyyy-mm-dd

Note: Using quotes around argument values is not required, but in some cases can be necessary. If you have an argument value like '0000-00-00' (an empty date) 1202 script assumes it should calculate its value, as it consists of only numbers and mathematical operators. Use single quotes around the value to prevent this.

Tip: You can nest commands. For example: $if[$date[][%Y] == 2014][The year is 2014]


You can define variables by using the 'var' command. When a model block is iterated - which happens when multiple content items are 'fed' to it - you can use the 'storevar' command to save variable values for the next iteration.

Once defined, variables are called like this:

{var: test}

Special values

In model blocks, but also in filter groups, you may need a relative date or time. You can use the following 'special values' in model blocks and filter groups:

  • {curdate}: the current date, formatted as yyyy-mm-dd.
  • {curdateutc}: UTC equivalent of {curdate}.
  • {curdatetime}: the current date and time, formatted as yyyy-mm-dd hh:mm:ss.
  • {curdatetimeutc}: UTC equivalent of {curdatetime}.
  • {curday}: the current day of the month (two digits, with leading zeros).
  • {curdayutc}: UTC equivalent of {curday}.
  • {curhour}: the current hour in 24-hour format (with leading zeros).
  • {curhourutc}: UTC equivalent of {curhour}.
  • {curmin}: the current minute (with leading zeros).
  • {curminutc}: UTC equivalent of {curmin}.
  • {curmonth}: the current month (with leading zeros).
  • {curmonthutc}: UTC equivalent of {curmonth}.
  • {cursec}: the current second (with leading zeros).
  • {cursecutc}: UTC equivalent of {cursec}.
  • {curtime}: the current time, formatted as hh:mm:ss.
  • {curtimeutc}: UTC equivalent of {curtime}.
  • {curyear}: the current year, formatted as yyyy.
  • {curyearutc}: UTC equivalent of {curyear}.
  • {customdate}: date, formatted as yyyy-mm-dd, with optional input (defaults to today). The input is defined using a colon and can have relative values, for example: {customdate: next monday}. Note the use of a textual datetime description.
  • {customdateutc}: UTC equivalent of {customdate}.
  • {customdatetime}: same as {customdate}, except the output is formatted as yyyy-mm-dd hh:mm:ss (includes time).
  • {customdatetimeutc}: UTC equivalent of {customdatetime}.

Note: Beware of timezone differences. All dates and times in your 1202 system are saved according to UTC (Coordinated Universal Time). They are shown in your local time (according to the system timezone setting) except when 'UTC' is explicitly stated. When using special values, always consider wether you want local or UTC time.

It is also possible to do calculations with special values. For this, you can use textual datetime descriptions. If you want to get the date of tomorrow:

{curdate + 1 day}

More info on parsing textual datetime descriptions can be found in the PHP documentation.


This is the current collection of 1202 script commands. We are constantly adding and updating commands, so check back often.


Return a date according to a specified format.




$date[2014-09-01][%e %b] // returns '1 sep'

When 'input' is not specified, the current local time is used. If you want UTC, use the 'dateutc' command.

Tip: You can include a timezone with your input, using for instance '2014-09-01 UTC' instead of '2014-09-01'. The 'date' command will then convert it to local time.

More formatting options can be found in the PHP documentation (the 'date' command utilizes the 'strftime' function).


Equivalent to the 'date' command, except it uses UTC when no 'input' is specified.


Conditionally execute a piece of code.




$if[1 == 1][This is true] // returns 'This is true'

You can use the following operators in your condition:

  • == equals
  • != does not equal
  • <> not greater and not smaller than (does not equal)
  • > greater than
  • < smaller than
  • >= greater than or equals
  • <= smaller than or equals

Furthermore, it is possible to combine conditions, using && for 'and', || for 'or', you can do calculations within conditions, and use parentheses to group conditions. For example:

$if[1 == 1 && (1 + 1 == 2 || 2 – 1 == 1)][This is true] // returns 'This is true'


Conditionally execute a piece of code. Also executes a piece of code if the condition evaluates to 'false'.


$ifelse[condition][if: code][else: code]


$ifelse[1 == 2][This is true][This is not true] // returns 'This is not true'

The same options and operators are available as for the 'if' command.


Import a model block into another model block.


$import[model block id][query string]


$import[20][doc-id=1&system-id=2] // returns the processed model block with id '20'

Note: Importing only works with model blocks that are requested remotely. They will not work within model block fields (specified in containers).


Return the integer value of a value.




$int[12.902] // returns '12'


Iterate over a field. This is useful when a field can have multiple values, which applies to fields from linked items.




$iter[{3-120: Text: Image: id}][{3-120: Text: Image: id} ] // returns a list of image id's

The 'code' is executed for each iteration.


Return the length (in characters) for a value.




$len[one] // returns '3'


Return a value in lowercase.




$lower[Make This Lowercase] // returns 'make this lowercase'


Return a value according as a number according to a specific format.

When not provided, the number of decimals is 0, the decimal separator ',', and the thousands separator '.'.


$numformat[input][decimals][decimal separator][thousands separator]


$numformat[1202.1202][2][,][.] // returns '1.202,12'


Return the first character's position of a value ('needle') within another value ('haystack').




$pos[test][this is a test] // returns '10'

When the input value was not found, the command will return '0'.

Tip: Use the 'pos' command to find out if a value occurs within an input value by checking if the result is equal or not equal to '0'.


Return a random (numeric) value.


$rand[min, max]


$rand[0, 10] // returns a number between 0 and 10


Replace a value within a value.




$replace[this][that][I want this] // returns 'I want that'


Comment or 'remark' for documentation purposes. These are stripped when output and therefore will only be visible within your 1202 system.




$rem[this section of the script does some calculations] // returns ''


Return a float rounded to the given number of decimals (defaults to '0').

Rounds up, away from zero, when it is half-way there, eg. 1.5 makes 2 and -1.5 makes -2.




$round[12.02][1] // returns '12.0'


Store a value to be used in a next iteration of the same model block. When content filters are linked to model blocks, it can 'feed' more than one item to a block. The block will then be iterated, with all values and variables cleared for each iteration. The 'storevar' command can save a variable between these iterations.




$storevar[{var: test}] // has no return value, stores the variable named 'test'

Note: You first have to set a variable with the 'var' command to be able to store it.


Return a value with all digits (0-9) stripped.




$stripnum[input with 123 digits in it] // returns 'input with digits in it'


Return a value with all tags stripped.




$striptags[input with a <strong>tag</strong>] // returns 'input with a tag'

Info: This command strips HTML and PHP tags.


Return part of a value, specified by a start position and length.


$substr[input][start, length]


$substr[one two three][4, 3] // returns 'two'

The 'start' and 'length' values can be negative, counting from the end of the string instead of the beginning. For examples, see the PHP substr documentation.


Strip whitespace from the beginning and end of a value and return it.




$trim[  too much space  ] // returns 'too much space'


Return a value with the first character in uppercase.




$ucfirst[first] // returns 'First'


Return a value in uppercase.




$upper[Make This Uppercase] // returns 'MAKE THIS UPPERCASE'


Return a decoded URL-encoded value. You can use this in conjunction with the 'urlencode' command.




$urldecode[a+simple+%26+short+test] // returns 'a simple & short test'


Return a URL-encoded value. You can use this in conjunction with the 'urldecode' command.




$urlencode[a simple & short test] // returns 'a+simple+%26+short+test'


Return a 'friendly' URL that is easy to read. It avoids 'clutter' from URL-encoding by replacing spaces for hyphens and simplifying accented letters and special characters.




$urlfriendly[al-ḥāsib al-miṣrī or the Egyptian calculator] // returns 'al-hasib-al-misri-or-the-egyptian-calculator'


Set a variable to use it later on in the same model block.




$var[test][some value] // sets the variable 'test' with the value 'some value'

You can access the set variable as a type of special field. The naming of these fields follows the pattern:

{var: name}

In the example above the variable is named 'test' and can thus be retrieved with:

{var: test}

Info: You can set the value of a variable with a string or number but also by using other variables or commands. This offers great opportunities for manipulating data.

Tip: If you want to save a variable to be used in later iterations of the same model block, use the 'storevar' command.