Liquid Examples
Here are some useful liquid examples.
Date and time
{{ "now" | date }} Default date according to current culture
{{ "now" | date_time }} No parameters possible - only current culture
Special date formats
If you need to deviate from the standard format. Formats can be viewed under http://strftime.net/.
{{ "now" | date: "%d.%m.%Y %H:%M" }}
{{ "now" | date: "%d.%m.%Y" }}
{{ "now" | date: "%A" }} {{ "now" | date: "%a" }} Weekday long/short
{{ "now" | date: "%-e" }} Day of the month without leading blank (note that - at %-e)
Add an hour (value in seconds)
{% assign correctedArrivalTime = Stop.ArrivalTimeWindowTo | date: '%s' | plus: 3600 | date: '%H:%M' %}
Number formatting via Culture
{{ 12.435984 | number: 'local2' }} 12,44
{{ 12.435984 | number: 'local4' }} 12,4360
{{ 12.435984 | number: 'local0' }} 12
{{ 12.43 | number }} 12,43 works without length but is not recommended
{{ 12.435984 | number: 'local2 kg' }} 12.44 kg (Fomat string can also be linked to a unit)
{{ undefined | number: 'local2 kg' }} Blank string
Currency selection via Culture
The number of decimal places is determined automatically
{{ 12.435984 | currency: 'EUR' }} 12,44 €
{{ 12.435984 | currency: 'JPY' }} 12 ¥ (Yen has e.g. no decimal places)
Special number formats
Instructions on https://www.npmjs.com/package/number-format.js (comma over period or comma is determined after the "rightmost" character of it)
{{ 12.435984 | number: '0,00' }} 12,44
{{ 12.435984 | number: '0.00' }} 12.44
{{ 12 | number: '0.00' }} 12.00
{{ 12 | number: '#.##' }} 12 - unnecessary decimal places are lost in the notation
{{ 1211111.430984 | number: '#.###,00' }} 1.211.111,43
{{ 12.430984 | number: '#.###,' }} 12
{{ 12.430984 | number: '0000,00' }} 0012,43 leading zeros can be specified with 0
{{ 12.430984 | number: '0,00 €' }} 12,43 €
{{ undefined | number: '0,00 €' }}
Text formatting
{{ 'ABC' | format: 'You can wrap {0} like this and'}} has the advantage that {{ '' | format: '--> {0} <--'}} doesn't output anything at all
{{ '10' | pad_start: 5 }} 10
{{ '10' | pad_start: 5, '0'}} 00010
List Operations
{% assign TestList = 'Foo.Fuu.Pattern.Test' | split: '.' %} Generates only test data
{{ TestList | map: 'length' }} = 3,4,34,5
{{ TestList | sum: 'length'}} = {{ TestList | map: 'length' | sum }}
{{ TestList | avg: 'length'}} = 11.5
{{ TestList | min: 'length'}} = 3
{{ TestList | max: 'length'}} = 34
{{ TestList | sort: 'length'}} = 34
{{ TestList | sort: 'length' | reverse | first }} = Danube Steamship Company
List grouping
{% assign GroupsByLength = TestList | group_by: 'length' %}
{% for Group in GroupsByLength -%}
String length: {{Group.Key}} Number of elements: {{ Group.Items.length }}
{% for GroupItem in Group.Items -%}
Item: {{ GroupItem }}
{% endfor %}
{% endfor %}
Barcode
{{ 'abc' | code128 }}
{{ 'abc' | idAutomation_code128 }} For the more complex font
{{ 'abc' | idAutomation_ean13 }}