Parra Liquid Template Engine

The Parra Liquid Templating Language is a powerful and flexible templating language based on LiquidJS. It enables developers to generate dynamic content by merging templates with data. Liquid can be used to dynamically insert data into various Parra products, like email and push notification templates. This user guide provides a comprehensive overview of how to use Parra Liquid Templating Language effectively.

Syntax

Parra Liquid Templating Language follows the LiquidJS syntax.

For security purposes, certain LiquidJS features such as custom tags and filters are disabled and all templating is executed in a restricted sandbox environment.

Here are some of the key concepts:

  1. Variables: Use {{ variableName }} to output the value of a variable.
  2. Filters: Apply filters to modify variable output. For example: {{ variableName | capitalize}}.
  3. Tags: Tags are used for control structures and logic. They are enclosed in {% %}. For example, {% if condition %} ... {% endif %}.
  4. Comments: Comments are not displayed in the output and are enclosed in {# #}.
  5. Loops: Use {% for item in collection %} ... {% endfor %} to iterate over a collection.

Examples

Assuming the user object:

{
    "id": 123,
    "name": "John Doe",
    "email": "john@example.com",
    "age": 30,
    "isAdmin": true,
    "address": {
        "city": "New York",
        "country": "USA"
    },
    "hobbies": ["Reading", "Gardening", "Cooking"]
}

Variables: Accessing user data using variables.

Name: {{ user.name }}
Email: {{ user.email }}

Filters: Applying filters to modify variable output.

Uppercase Name: {{ user.name | upcase }}

Tags: Using control structures with tags.

{% if user.isAdmin %}
Welcome, Administrator!
{% else %}
Welcome, Guest!
{% endif %}

Comments: Adding comments to the template (not displayed in output).

{# This is a comment. #}

Loops: Looping over user's hobbies.

{% for hobby in user.hobbies %}
- {{ hobby }}
{% endfor %}

Conditional Output: Showing user's age if it exists.

{% if user.age %}
Age: {{ user.age }}
{% else %}
Age: Not specified
{% endif %}

Nested Data: Accessing nested data in the user object.

Address: {{ user.address.city }}, {{ user.address.country }}

Math Operations: Performing math operations.

Next year, John will be {{ user.age | plus: 1 }} years old.

Includes: Reusing code with includes.

{% include 'header.liquid' %}
<h1>Hello, {{ user.name }}!</h1>
{% include 'footer.liquid' %}
First letter of the name: {{ user.name | firstLetter }}

These are just a few examples of how you can use LiquidJS to dynamically generate content and manipulate data in your templates. The possibilities are vast, and you can tailor the templates to suit your specific needs.

Conclusion

Parra Liquid Templating Language offers a flexible and powerful way to generate dynamic content in the Parra dashboard. By following the instructions in this user guide, you can create and use templates with ease. Happy templating!

Was this page helpful?