Skip to content

Code Islands ​

In its simplest form, a template is a text that will be sent as message as is.

However, the whole point of the template engine is the ability to format this text in a given way, use control structures (conditions or loops) inside it, and even perform some actions. The "code islands" are used to do that.

Code ​

Code islands begin with {% and ends with %}, just as simple as that. Tags are used inside code constructs to implement a control structures (conditions or loops), declare variables and much more.

JuniperBot Template
{% tag %}

Each code construct can perform only single operation or declare part of a control structure.

The logical sequence is formed by using many separate islands of code for each individual operation or part of the control structure.

Whitespace Control ​

Tied up with the code island syntax is another syntactically enabled feature, the white space control functionality. This allows one to remove white spaces before or after a code island. In order to accomplish that, append/prepend the symbol - to the beginning/ending of the code island. Let's take for example:

JuniperBot Template
{% if (1 == 1) -%}     text     {%- endif %}

Such code will produce text without white spaces.

Output ​

In JuniperBot Template Engine there is only one way to write the value of variable or an expression to the output. That is accomplished with the print operation as shown below:

JuniperBot Template
{{ expression }}

Note that output also support the white space control feature, using the same approach as per code islands:

JuniperBot Template
{{- expression -}}

Comments ​

In template engine you can add comments that will not be printed anywhere:

JuniperBot Template
{# This is the content of the comment.
And it can be a multi-line content. #}

Again, comment constructs also support white space control feature in the same way as code islands:

JuniperBot Template
{#- Your awesome comment -#}

All rights sniffed.