You can format merge fields using "filters". There are many filters available and each filter has various options:
Dates
To format dates, you can use the date
filter, which looks like: {{ event.date | date }}
. The line in the middle is the "pipe" character.
By default, this will format the date in North American "medium date" format (i.e. "December 31, 2023"). If you want to customize the formatting of the date (or time), you can use the first parameter on the date filter. For example, if you want to show the date in US "short form" (i.e. 12/31/2023):
{{ event.date | date("m/d/Y") }}
Or, if you only want to show only the time (in this case 24-hour time), you can do:
{{ event.time.start | date("H:i") }}
All available date and time format options are available here.
Another consideration is timezone. The majority of dates stored in Lumify are stored in the UTC timezone and are automatically converted to the system timezone configured under Settings > Localization when you use the date
filter.
If you don't want the timezone to be automatically converted, you can use the second parameter on the date filter, like this:
{{ event.date | date("F j, Y", "local") }}
Or you can achieve the same result using named parameters, which are sometimes easier to read:
{{ event.date | date(tz="local") }}
This tells Lumify that the time is already in a local timezone and does not require conversion. The best example of where this is appropriate is on {{ event.date }}
, {{ event.time.start }}
or {{ event.time.end }}
, which are already stored in local time (i.e. not stored in UTC). The available options for timezones are:
- sys (default) will convert the date and time to your configured system timezone
- user will convert the date and time to the current user's timezone
- local will not convert date and time
Currency
To format currency, you can use the money
filter. This will automatically use the local settings from Settings > Localization to format your document with the appropriate currency.
{{ invoice.deposit_amount | money }}
You can also use the forceDecimals
parameter to always show the smallest denomination in your local currency (e.g. pennies):
{{ invoice.deposit_amount | money(forceDecimals=true) }}
Other basic text formatting filters
There are many filters to perform basic text transformations:
firstName
: Shows a contact's first namelastName
: Shows a contact's last nameplural
: Converts a word to "plural"singular
: Converts a word to "singular"upper
: Transforms text to uppercaselower
: Transforms text to lowercasetitle
: Transforms text to "Title Case"capitalize
: Transforms text to "Sentence case"slug
: Transforms text to "a-slug-format"
Default replacement
If a merge field is empty, you can use the default
filter to provide a default (e.g. {{ event.location.name | default("TBD") }}
). If you don't provide a default, the merge field will appear blank.
Turn arrays into simple lists
When you have a list of entities (i.e. an array), you can use the join
filter to merge that list into, for example, a simple comma-separated list:
{{ contact.tags | join(",") }}
You can also use the second parameter on the join filter to customize how the list is joined. If provided, the second parameter will be used instead of the first which will turn:
{{ contact.tags | join(",", ", and") }}
Into this: "Tag 1, Tag 2, and Tag 3."
For more advanced users, you can also combine the join filter with the map
filter. This is useful in cases where the joined data is complex:
{{ event.contacts | map(contact => "#{contact.user.name}") | join(", ") }}
This is equivalent to the concept of mapping arrays in Javascript or PHP.