Types

Overview

ZML Objects can have one of five types.

  • String

  • Number

  • Boolean

  • Nil

  • Array

You can initialize variables in ZML with the assigned or capture tags.

String

Common strings are user properties like first_name.

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

Input

{% assign a_string = "Hello World!" %}

Number

Numbers include floats and integers. Common numbers are user properties like loyalty_points. When assigning a number to a variable, do not wrap the number in quotes or it will be considered a string.

Input

{% assign a_number = 25 %}

Boolean

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

Input

{% assign foo = true %}

Nil

Nil is a special empty value that is returned when ZML code 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 ZML tags that check the truthfulness of a statement. In the following example, if the user property first_name does not exist (that is, first_name returns nil), ZML will not print the greeting:

Input

{% if first_name %}

Hello {{ first_name }}!

{% endif %}

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

Input

Hello {{ first_name }}!

Output

Hello !

Array

To access all the items in an array, you can loop through each item in the array using an iteration tag.

Input

<!-- subscription_preferences = "newsletter", "promotions" --> 

{% for preference in subscription_preferences %}

{{ preference }}

{% endfor %}

Output

newsletter promotions

Accessing specific items in arrays

You can use square bracket [ ] notation to access a specific item in an array. Array indexing starts at zero.

Input

<!-- subscription_preferences = "newsletter", "promotions" --> 

{{ subscription_preferences[0] }}

{{ subscription_preferences[1] }}

Output

newsletter

promotions

Initializing arrays

You cannot initialize arrays using only ZML. You can, however, use the split filter to break a string into an array of substrings.