Leanplum templating language

Personalize content and insert values using our jinja-based templating language

Leanplum’s templating language is based on Jinja, a popular templating system that is both simple and powerful. Templates give you the highest degree of control to customize and personalize the content you send to your users.

To use templates, simply mark up any variable or message field with special syntax. Insert variables by surrounding them with {{ }}. For example,

{{ userAttribute.firstName }}

inserts the user attribute labeled “firstName”.

Tags are marked with {% %}. They control the logic of the template, and can perform conditional statements, loops, macros, and more.

Here is an example of a loop:

{% for item in linkedData.menu %}
   <li><a href="{{ item.href }}">{{ item.name }}</a></li>
{% endfor %}

Variables

Template variables, not to be confused with Leanplum’s content variables, contain the data used to render the template. You can define your own variables as well as use built-in variables. Variables can also be expressions, which evaluates to a new variable. Anything in a {{ }} gets evaluated and inserted into the final content.

Some variables are actually a collection of attributes, which can be accessed using a dot (.), or with subscript notation ([]). For example, userAttributes is a collection of all of the user attributes for the current user. If you want to insert the value of an attribute named firstName, either of these will work:

Welcome, {{ userAttribute.firstName }}
Welcome, {{ userAttribute['firstName'] }}
If the attribute has a space in the name, you must use the subscript notation:

Welcome, {{ userAttribute['First name'] }}


Next

See more on Leanplum's templating capabilities.