How to create a Twig snippet plugin for server-side code

What is Twig and why use it?

Twig is a powerful HTML template engine. It offers all the features already available for the rich text editor, such as merge fields, along with other extras (e.g. conditional logic, loops, escaping strings).

Twig snippet plugin

The Twig snippet plugin allows to display a block of static HTML, Javascript or Twig code in a given slot. While PHP code will not be executed for security reasons, Zenario core functions can be used in a Twig snippet.

Examples

The following code will display the server time and timezone.

Twig snippet server time and timezone

Result:

Twig snippet server time and timezone result

 

Usage

Comments

Comments can be used to explain how a block of code works, mark different sections or any other reason.

These comments only appear in the source code and are never displayed to users.

To use a comment, put the {# ... #} tags around the text.

Twig snippet comment

Variables

Variables can be set using the {% set %} tag.

Twig snippet variable

These variables may later be used in conditional statements.

Loops

Twig supports looping over items in a sequence.

The following code will display all numbers 0-10 in one row:

Twig snippet numbers 0 to 10