Intro

The SovLabs Template Engine allows for static text in combination with dynamic content such as vRA custom properties and/or custom logic

The SovLabs Template Engine is organized into Outputs, Tags and Filters.

Outputs

Outputs render an expression. Outputs and variable names are denoted by double curly braces: {{ and }}

Input
  • foobar = "Hello world"
    {{ foobar }}
Output
  • Hello world

The SovLabs Template Engine renders the content of the object foobar, and that object contains the output Hello world


Tags

Tags create the logic and control flow for templates. Tags are denoted by curly braces and percent signs: {% and %}

The markup used in tags do not produce visible text. Tags allows one to assign variables and create conditions and loops

Input
  • user.name = 'John Doe'
    {% if user.name == 'John Smith' %}
    Hello John Smith
    {% else %}
    Hello stranger
    {% endif %}
Output
  • Hello stranger

Filters

Filters change the rendering of the Output. Filters are used within an Output and are separated by a |

Input
  • {{ 'Hello' | append: ' world' }}
Output
  • Hello world

Multiple filters can be used on one output. The filters are applied from left to right.

Input
  • {{ 'world!' | capitalize | prepend: 'Hello' }}
Output
  • Hello World!

Types

SovLabs Template Engine can have one of 5 types:


String

Declare a string by wrapping a variable’s value in single or double quotes

{% assign my_string = "Hello world" %}

Number

Numbers include floats and integers

{% assign my_int = 25 %}
{% assign my_float = 39.756 %}

Boolean

Booleans are either true or false. No quotations are necessary when declaring a boolean

{% assign foo = true %}
{% assign bar = false %}

Nil

Nil is a special empty value that is returned when the output has no results. It is not a string with the characters “nil”.

Nil is treated as false in the conditions of if blocks and other tags that check the truthfulness of a statement.

In the following example, if the user does not exist (that is, user returns nil), SovLabs Template Engine will not print the greeting:

{% if user %}
  Hello {{ user.name }}!
{% endif %}

Tags or outputs that return nil will not print anything to the page.

Input
  • The current user is {{ user.name }}
Output
  • The current user is

Array

Arrays hold lists of variables of any type

Accessing items in arrays

To access all the items in an array, loop through each item in the array using iterations (e.g. for tag)

{% for user in users %}
  {{ user }}
{% endfor %}

Accessing specific items in arrays

Use square bracket [ and ] notation to access a specific item in an array. Array indexing starts at zero.

{{ users[0] }}

Initializing arrays

The SovLabs Template Engine is unable to initialize arrays.

However, use the split filer to break a string into an array of substrings


References: Shopify Liquid: Wiki