After reading this you'll have learned:

  • What the Liquid Template language is;
  • How the language works;
  • What liquid tags and outputs are.

The Liquid template language (or: liquid) is an open-source template language created by Shopify. You can use it in Betty Blocks to create dynamic templates.

With liquid, you are able to create fewer templates for more purposes. Liquid can access all available variables, and display their data. It's main purpose is to display dynamic sets of data.

Two types of markup

There are two types of markup in Liquid: Output and Tag. Output markup is meant to simply display data, whereas Tags are used for programmatic logic in your template.

What we did in the example was using Output. The double curly brackets indicate output. #{{ }} You can use a lot of functions to manipulate the way the data is shown using a pipe  | 


Let's say you want to create a PDF template for an invoice.

You'd want to display the invoice number, but every invoice number is a different number of course. You'd want to add the invoice number as a dynamic variable on your template. Since you're creating a PDF file as a property on a model, you've got a current object. In templates you can access the current object as record. So if you want to place the invoice number of the record on the PDF, you can use liquid:

#{{ record.invoice_number }}

You'd probably also want to show the orderlines, connected to the current record, on your PDF. You can achieve this with liquid tags:

{% for ol in record.orderlines %}
#{{ ol.amount }}x  #{{ }} = #{{ol.price }}
{% endfor %}

And to complement the invoice, you'd want to show the total price of all orderlines combined:

#{{ record.orderlines | sum: "price" }}

The last example shows the use of a liquid function. We've got dozens of functions at your disposal. These can be found in the Liquid Template Reference. Make sure to check these out too!

Did this answer your question?