Skip to main content

CircleScript

 

CircleScript is a macro substitution language that uses [$path] syntax to reference content stored in the CMS (Content Management System.) The same syntax can also be used to reference “local definitions” or simple tags.

Content replacement and concatenation language

Function Description Syntax
Simple header example Create a header file and store it in the CMS under “/headers/myheader.html” and then pull that content into my mailing with the dollar-tag syntax.
[$/headers/myheader.html]

-> contents of "myheader.html"

$using directives Start your content with one or more $using directives. Following the above example:
$using /headers
[$myheader.html]

-> contents of "myheader.html"

Local definitions Make definitions at the top of your content to be available when evaluating subsequent content.
$game=chess
Thanks for playing [$game]!

-> Thanks for playing chess!

Recursion Whenever a dollar-tag is resolved, it’s value is also evaluated.
$greeting=Hello [$title]!
$title=chief
[$greeting]

-> Hello chief!

CMF data files There are special Content Management Files (.cmf) generally referred to as “data files” that can be used to define multiple (even thousands) of definitions within the same file. From CircleScript's perspective, a CMF file is just like a directory full of individual definitions.
$using /data/mydata <- this refers to "/data/mydata.cmf"
[$offers]

-> Because of the $using directive, when the system tries to resolve [$offers], it will first look in “/data/mydata.cmf”, if it exists.

Templates You can define an html with all of the content that remains the same across mailings. This contains dollar-tag references that template must resolve for each individual mailing (or each individual recip.) You then upload a data (.cmf) file with all the specific definitions. This data file is updated before each mailing.
$using /data/mydata
[$/templates/mytemplate.html]
Defaults - Coalescence There are two simple mechanisms for providing defaults: Coalescence and Guard. These require a local definition. Coalescence operations can be chained.
$name=[-_firstname-]??Friend
Hello [$name]

-> If [-_firstname-] is not blank, it will be used. If it is blank, "Friend" will be used instead.

Defaults - Guard There are two simple mechanisms for providing defaults: Coalescence and Guard. These require a local definition.
$level_message=?[-level-]:You are at level [-level-]!
[$level_message]

-> If [-level-] is not blank (e.g. 7), [$level_message] will resolve to "You are at level 7!".

If [-level-] is blank, $level_message] will also be blank.

Logic - AND

Coalescence and guard syntax can be used to implement simple AND logic.

Use BLANK to represent false and ANYTHING ELSE to represent true.

Note: any non-blank value ("1", "yes", "42") will represent TRUE.

A missing tag will also be evaluated to within the context of a coalescence or guard expression.

$p1=true
$p2=true
$p3=
$p1and2=?[$p1]:?[$p2]:yes??no
$p2and3=?[$p2]:?[$p3]:yes??no
1 and 2 : [$p1and2]
2 and 3 : [$p2and3]

-> 1 and 2 : yes

2 and 3 : no

Logic - OR

Coalescence and guard syntax can be used to implement simple OR logic.

Use BLANK to represent false and ANYTHING ELSE to represent true.

Note: any non-blank value ("1", "yes", "42") will represent TRUE.

A missing tag will also be evaluated to within the context of a coalescence or guard expression.

$p1=true
$p2=
$p3=
$p1or2=?[$p1][$p2]:yes??no
$p2and3=?[$p2][$p3]:yes??no
1 or 2 : [$p1or2]
2 or 3 : [$p2or3]

-> 1 or 2 : yes

2 or 3 : no

Iteration ($each directive) Use the $each directive to repeat a block of code multiple times.
$each i:[1..3]
Repeat me!

-> Repeat me!Repeat me!Repeat me!

Iterator in Path ($each directive) Use the $each directive to insert iteration in paths.
$each i:[1..3]
[$content_[$i]]

-> [$content_1][$content_2][$content_3]

Implicit Path Iteration ($each directive)

Use the $each directive to insert iteration in paths.

Note: [$content_*] becomes shorthand for [$content_[$i]]

$each content_[1..3]
[$content_*]

-> [$content_1][$content_2][$content_3]

Qualifying the Each Block ($each directive)  
$each content_[1..100]
?[$content_*]:<p>[$content_*]</p>

-> <p>[$content_1]</p><p>[$content_2]</p>... until [$content_N] is blank or missing

Iteration in a Sub Context ($each directive) Loop through a block of content that's in the middle of some other content, put the content that's to be repeated into a sub-context, and makethe first line an $each directive.
<table>
[$$$each row:[1..100]
?[$c[$row]_1]:<tr>[$$$each col:[1..100]
?[$c[$row]_[$col]]:<td>[$c[$row]_[$col]]</td>$$]</tr>
$$]</table>

-> <table>

<tr><td>[$c1_1]</td><td>[$c1_2]</td>...</tr>

<tr><td>[$c2_1]</td><td>[$c2_2]</td>...</tr>

...

</table>

Short Circuiting ($each directive) The $each directive will stop once it's block produces no output. For example, if only $content_1 is defined.
$each content_[1..1000]
[$content_*]

-> [$content_1]

Short Circuiting ($each directive with $guard) The $each directive will stop once it's block produces no output. For more complex blocks, use the ?[$guard]: syntax.
$each content_[1..1000]
?[$content_*]:<p>[$content_*]</p>

-> <p>[$content_1]</p>

CircleScript functions

Note: CircleScript functions follow the format [$functionName(args)]

 

Function Description Syntax
base64 Base-64 encode a string. This is useful for obfuscating link parameters.
[$base64(arg)]
contains

Write alternate content based on whether one string value contains another.

If [on_equal] is not specified, "true" will be used. If [otherwise] is not specified, "" (blank) will be used.

[$contains(value,substring,[on_equal],[otherwise])]
Example: [$contains([-domain-],yahoo,[$/legal/yahoo])].
currentdate Write the current date, using the given format string, or 'MM/dd/yyyy' if not specified.
[$currentdate([format_string])]
dynamic_title_web_fetch

Fetch content from a given URL and extract a title.

If the fetched content contains <title> tags, then their contents will be extracted, otherwise the entire contents will be written.

URL must start with "http://" or "https://"

[$dynamic_title_web_fetch(URL)]
ends_with

Write alternate content based on whether one string value ends with another.

If [on_equal] is not specified, "true" will be used. If [otherwise] is not specified, "" (blank) will be used.

[$ends_with(value,suffix,[on_equal],[otherwise])]
Example: [$ends_with([-time-],AM,morning,evening)].
escapehtml Escape HTML characters in a string.
[$escapehtml(arg)]
Example: [$escapehtml(<name>)] -> &lt;name&gt;
formatdate Write the given date, using the given format string, or 'MM/dd/yyyy' if not specified.
[$formatdate(date,[format_string])]
greater_than

Write alternate content based on whether one integer is greater than another.

If [on_equal] is not specified, "true" will be used. If [otherwise] is not specified, "" (blank) will be used.

[$greater_than(lhs,rhs,[on_equal],[otherwise])]
Example: [$gt([-points-],10000,[$/message/high-points])]
if_equal

Write alternate content based on string equality.

If [on_equal] is not specified, "true" will be used. If [otherwise] is not specified, "" (blank) will be used.

[$if_equal(lhs,rhs,[on_equal],[otherwise])]
Example: [$if_equal([-domain-],yahoo.com,[$/messages/yahoo],[$/messages/default])]
less_than

Write alternate content based on whether one integer is less than another.

If [on_equal] is not specified, "true" will be used. If [otherwise] is not specified, "" (blank) will be used.

[$less_than(lhs,rhs,[on_equal],[otherwise])]
Example: [$lt([-points-],10000,[$/message/low-points])]
money

Write the given decimal value using the default or specified formatting.

To round to the nearest dollar, provide the format "%1$,.0f" as the second argument.

[$money(decimal_value,[format])]
Example: $[$money([-savings-])] -> $1,234.50.
multiply

Multiply the given arguments. Works for integer and decimal values.

Returns a blank if any of the arguments are blank or are not valid integers.

[$multiply([n1],[n2],...)]
starts_with

Write alternate content based on whether one string value starts with another.

If [on_equal] is not specified, "true" will be used. If [otherwise] is not specified, "" (blank) will be used.

[$starts_with(value,prefix,[on_equal],[otherwise])]
Example: [$starts_with([-code-],XP-,[$/message/xp-message],[$/message/default-message)].
title Title Case a string. If the string has multiple words, the first letter of each word is capitalized.
[$title(arg)]
unescapehtml Un-escape HTML characters in a string.
[$unescapehtml(arg)]
Example: [$escapehtml(&lt;name&gt;)] -> <name>
urlencode URL Encode a string. This is useful for encoding link parameters that may contain special characters.
[$urlencode(arg)]
urlencode2 URL Encode a string twice. Same as URL encode, except that the string is encoded twice.
[$urlencode2(arg)]
Powered by Zendesk