Intro

The SovLabs Template Engine enables injection of values for vRA Properties into the SovLabs profiles and the resulting build processes. It can combine static text with vRA custom properties and provides constructs for flow control, logic, iteration and transformation to provide a powerful layer of dynamically controlled metadata which simplifies the management of your configurations in vRA. No need to create multiple configurations to accommodate different hard-coded values for fields. With the SovLabs Template Engine, values can be decided on the fly based on selections at request time or other properties set on other components in vRA, such as custom properties on Business Groups, Reservations, and vCenter endpoints.

SovLabs Template Engine Concepts

A SovLabs Template object is a placeholder which is written in SovLabs Template Engine syntax. This placeholder can be used where it's supported in the SovLabs product to manipulate and transform vRA property data into output that can be used by the modules during the vRA build lifecycles.

The SovLabs Template can be an Output placeholder or a logic placeholder or a combination.

An Output placeholder is a property enclosed in double curly braces. {{ my_propertyname }} The output placeholder can also contain Filters which can modify the output before it is rendered.

Output placeholders

An Output placeholder extracts the value of the property inside the curly braces, passes it through any filters, and renders the transformed value.

In this example, foobar is a vRA property. There are no filters, so the SovLabs Template Engine renders the value of that property, which is Hello world

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

Filters

Filters are used within Output placeholders to transform the data before it’s rendered

In this example, the vRA property foobar is passed through the upcase filter. The Template Engine renders the value of that property after passing thorugh the filter. HELLO WORLD

Input
  • foobar = "Hello world"
    {{ foobar| upcase }}
Output
  • HELLO WORLD

Another example:

Input
  • foobar = "hello"
    {{ foobar | append: ' world' }}
Output
  • hello world

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

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

Logic and Tags

Logic placeholders provide logic and control flow for templates. Logic placeholders are enclosed by by curly braces and percent signs: {% and %}

The logic placeholder is enclosed in {% %} and contains Tags, which are logical constructs like if/else, case statements, loops, etc. These provide logic and flow control capabilities for transforming the value before rendering

Tags

Tags are used inside the Logic placeholder to perform logical and control operations. The markup used in tags does not produce visible text.

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

For a more SovLabs-specific example, you could write a template to pick the correct SovLabs IPAM profile based on a vRA property called “Environment” instead of hard-coding the Custom Property SovLabs_IPAMProfile_nic0 to a specific profile. You would create the custom property SovLabs_IPAMProfile_nic0 on your vRA blueprint and put the template in the Value field:


Input
  • Environment = "production"
    {% if Environment == 'production' %}IPAM_profile_prod{% elsif Environment == 'development' %}IPAM_profile_development{% elsif Environment == 'QA' %}IPAM_profile_QA{% else %}IPAM_profile_default{% endif %}
Output
  • IPAM_profile_prod

Keep in mind that spaces and other characters show up as literals in the output, so if your template changes like this:


Input
  • Environment = "production"
    {% if Environment == 'production' %}X_ IPAM_profile_prod YY{% elsif Environment == 'development' %}IPAM_profile_development{% elsif Environment == 'QA' %}IPAM_profile_QA{% else %}IPAM_profile_default{% endif %}
Output
  • X_ IPAM_profile_prod YY

When you see a reference to a property enclosed in double curly braces in the documentation for the modules, e.g. {{ my_propertyname }}, that implies use of the SovLabs Template engine to transform that property and use its resulting value in that place. In SovLabs configurations in general, most fields are "templatable", which means you can substitute a valid Template Engine template in place of a hard-coded value. Not only can you template many fields inside the SovLabs configurations, you can also use a template to set the value of a SovLabs Custom Property.

To see all the functions available in the SovLabs Template Engine, see the list in the left pane.


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