Skip to main content

Using Liquid tags

Control the information shown in your templates with conditions, loops and variables.

Tags are instructions that tell a template what to show, what to leave out or what to repeat. For example, you can show a telephone number only when one is recorded, or list all the products on a quotation. Copy the brackets and tag names exactly; change only the wording you want to display.

Comparison and logical operators

These symbols and words help a tag ask a question. For example, == asks “is this equal to?”, != asks “is this different?”, and < asks “is this less than?”. Use “and” when both conditions must be true; use “or” when either one can be true. They are useful inside an “if” or “unless” tag, for example to show a message only when an opportunity total is below a particular amount.

Operator

Meaning

==

Equals

!=

Does not equal

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

and

Both conditions are true

or

Either condition is true

For example, here we use less than:

{% if order.charge_excluding_tax_total < 100 %}
Spend some more money with us.
{% endif %}

Example output

If the total excluding tax is 80: Spend some more money with us.

If the total is 100 or more: nothing is shown.

Conditions: if, else and elsif

Use these when you want different information to appear depending on what is recorded in OnRent Events. “if” checks a condition, “else” provides an alternative, and “elsif” checks another possibility.

In the example below, the document either shows a telephone number or explains that none is recorded.

{% if customer.telephone == blank %}
We do not have a telephone number on record.
{% else %}
{{ customer.telephone }}
{% endif %}

Example output

If no telephone number is recorded: We do not have a telephone number on record.

If one is recorded: 020 7946 0000

Use elsif to check more than one possible value. The opportunity status values below are taken from the object reference:

{% if order.status == 0 %}
Open
{% elsif order.status == 1 %}
Provisional
{% elsif order.status == 5 %}
Reserved
{% endif %}

Example output

For an opportunity with a status of 1: Provisional

Unless

“unless” means “show this only if the condition is not true”. Here, a discount message is shown only when the discount total is not zero.

Use unless to show content when a condition is not met.

{% unless order.discount_total == 0 %}
A discount has been applied.
{% endunless %}

Example output

If the discount total is not zero: A discount has been applied.

If the discount total is zero: nothing is shown.

For: repeat content

Use “for” to repeat the same section for every entry in a list. For example, you can automatically show each product on an opportunity instead of adding each product by hand.

This example creates a list entry for each opportunity item:

{% for item in order.items %}
{{ item.name }}
{% endfor %}

For an opportunity with three items:

Projector

Speaker

Extension cable

Cycle: alternate values

Use “cycle” to alternate between values as a list is displayed. It can help with alternating row formatting. This is optional for more advanced layouts.

Use cycle inside a loop to alternate output values, such as CSS class names:

{% for item in order.items %}
{% cycle "odd", "even" %}: {{ item.name }}
{% endfor %}

Example output

odd: Projector

even: Speaker

odd: Extension cable

Assign and capture

These let you save information under a name to use again in the same template. “assign” saves a value such as a number or phrase. “capture” saves a whole piece of text, including dynamic information.

Assign stores a value in a variable. Capture stores generated text for later use.

{% assign tagline = "Cloud Rental Management Software" %}
{{ tagline }}
{% capture greeting %}
Hello {{ customer.name }}, thank you for ordering from {{ company.name }}!
{% endcapture %}
{{ greeting }}

Example output

Cloud Rental Management Software

Hello Jane Smith, thank you for ordering from Example Events Ltd!

Case: compare several values

Use “case” when a field can have several possible values, such as an opportunity status. Each “when” checks one value and shows its matching message. “else” provides a fallback.

{% case order.status %}
{% when 0 %} Open
{% when 1 %} Provisional
{% when 5 %} Reserved
{% when 20 %} Active
{% when 40 %} Completed
{% when 50 %} Cancelled
{% when 60 %} Lost
{% when 70 %} Dead
{% when 80 %} Postponed
{% else %} Other status
{% endcase %}

Example output

For an opportunity with a status of 1: Provisional

For a status of 20: Active

Comments

Comments are notes for someone editing a template. They do not appear in the finished document. Any content that you put between {% comment %} and {% endcomment %} tags is turned into a comment.

{% comment %}
This note does not appear on the document.
{% endcomment %}

Example output

Nothing is shown. The note is visible only to people editing the template.

Did this answer your question?