๐Ÿ“˜ Liquid Template Reference

Below are common Liquid concepts and examples. Use the "Try it out" link to load it directly into LiquidTester

1. Simple Variable Output

Description: Outputs the values of input variables name and lastname.

JSON input:

{"name": "Dean","lastname": "Ledet"}

Template:

{ "fullName": "{{name }} {{lastName}}" }

Result:

{"fullName": "Dean Ledet"}

2. Filter: Upcase

Description: Uses the Upcase filter to print the variable name in uppercase.

JSON input:

{"name": "Dean","lastname": "Ledet"}

Template:

{ "firstNameUpperCase": "{{name" | Upcase}}" }

Result:

{"firstNameUpperCase": "DEAN"}

3. Date Formatting

Description: Formats a datetime using the Date filter.

JSON input:

{"datetime":"Friday, May 16, 2025 2:42 PM"}

Template:

{ "datetime": "{{ datetime | Date: "yyyy-MM-dd HH:mm:ss" }}" }

Result:

{"datetime":"2025-05-16 14:42:00"}

4. Looping Through a Collection

Description: Iterates over a list of products and prints their name and price. Utilizes unless forloop.last to determine whether a comma should be placed at the end of the product.

JSON input:

{"products":[{"name":"Apple","price":10},{"name":"Banana","price":5}]}

Template:

{ "fruits": "{% for product in products %}{{ product.name }} ({{ product.price }}){% unless forloop.last %}, {% endunless %}{% endfor %}" }

Result:

{"fruits":"Apple (10), Banana (5)"}

5. If/Else Condition

Description: Shows a different message depending on the value of age.

JSON input:

{"age":20}

Template:

{ "message": "{% if age >= 18 %}You are an adult.{% else %}You are a minor.{% endif %}" }

Result:

{"message":"You are an adult."}

6. Chained Filters (Slugify Example)

Description: Trims whitespace, converts to lowercase, and replaces spaces with dashes - useful for creating slugs.

JSON input:

{"title":" Hello World "}

Template:

{ "title": "{{ title | Strip | Downcase | Replace: " ", "-" }}" }

Result:

{"title":"hello-world"}

7. PEPPOL Invoice Transformation

Description: A practical example that transforms JSON data into an EN 16931 UBL Invoice 1.3.13 XML document also known as PEPPOL BIS Billing 3.0 using a Liquid template. This showcases advanced techniques such as loops, conditions, and handling of XML namespaces.

The input is invoice data in JSON format, and the template generates a fully compliant PEPPOL UBL XML invoice, extracting and formatting key details such as supplier info, invoice number, dates, totals, and line items.


Back to Liquid Testing