Syntax and Literals
This is an overview of the syntax you need to be familiar with to use the template directives; alongside explanations of what the different kinds of literals available are and how they look.
On this page:
Syntax
When writing your code you must make sure that you are using the right syntax otherwise you may create a parse error, this will lead to your campaign overview showing a red stop sign, signifying that there is a problem.
Tags
Code will need to put within the character sequences [* ... *]; this is to separate the code from text or HTML. You can either use this syntax on every line or over many by ensuring there is a ; at the end of each line, so that the code knows the line has ended.
[* darwin_quote = "I love fool's experiments, I am always making them." *]
[* darwin_quote.upper *]
Output: I LOVE FOOL'S EXPERIMENTS, I AM ALWAYS MAKING THEM.
OR
[* darwin_quote = "I love fool's experiments, I am always making them."; darwin_quote.upper; *]
Code Blocks
When you do something within your code, such as an IF statement or FOREACH loop, you must end it. To do this you include [* END *] on the last line of your Code Block (or END; *] if you're going over multiple lines). If you don't do this you will create a parse error and your campaign will not show in the overview.
[* darwin_quote = "I love fool's experiments, I am always making them." *]
[* darwin_array = darwin_quote.split(', ') *]
[* FOREACH line IN darwin_array *]
[* line *]
[* END *]
Output:
I love fool's experiments
I am always making them.
| html
When writing your code it is best practice to add the filter | html at the end; this is because it changes <, >, & and " to <, > ,& and ", which will protect your code from being interpreted as html tags.
Comments
You can apply a comment to a line by using a hash #. This denotes the whole line as a comment and will not be read as code.
[* darwin_quote = "I love fool's experiments, I am always making them.";
# this is a quote from Charles Darwin;
darwin_quote;
*]
Output: I love fool's experiments, I am always making them.
Literals
Literals make up what your variables are, they are the content that you do stuff to.
Strings
String literals are denoted by ' ' and need to encase letters. When you GET this string it will output whatever it is set to.
For example:
[* my_string = 'this is an example string';
my_string;
*]
Output: this is an example string.
Escaping
Escaping allows you to use certain characters that, without escaping, have a certain function. For example, escaping quotation marks within a string will prevent the code from thinking there are two strings, separated by unreadable text. To escape something all you do is put a \ before it, for example:
[* my_string = 'Shakespeare wrote \"What is the city but the people?\" in one of his plays' *]
Digits
Numbers don't need quotation marks, they are understood to be numbers when they are written: [* my_number = 4 *]
However, if you have digits that aren't a number (like binary or a pin code) you will need to place these in a string so that they aren't treated as a mathematical symbol.
For example:
[* phone_number = '07700 456 789' *]
Arrays
Arrays are lists of data, they are able to hold multiple values which you can search through using certain loops or conditions which are described later.
[* my_array = ['Wordsworth', 'Coleridge', 'Milton', 'Pope'] *]
Hashes
Hashes allow you to create data which has keys and values. This in turn allows you to search through the values for the key results or a key result for its value. They are contained within braces and use = to set the value.
[* my_hash = { 'Batman' = 'The Joker', 'Professor X' = 'Magneto', 'Daredevil' = 'Kingpin' } *]