Formatting template variables
Waypoint uses LiquidJS to populate the dynamic parts of the template (see template variables). This means all of the standard Liquid filters are available to use.
Below are some of our favorites:
Default
Use | default
to specify a fallback in case a value doesn’t exist (without having to use a more complex conditional). Example:
Data
{ "user": { "fullName": "" }}
Input
Hi {{user.fullName | default: 'there'}}
Output
Hi there
Capitalize
Use | capitalize
to force the first character of a string capitalized. Example:
Data
{ "user": { "role": "admin" }}
Input
{{user.role | capitalize}}
Output
Admin
Truncate
Use | truncate
to shorten a string down to the number of characters passed as an argument. Example:
Data
{ "website": { "description": "Build and send emails, faster than ever." }}
Input
{{ website.description | truncate: 25 }}
Output
Build and send emails...
Custom filters
Waypoint also offers set of custom built-in filters that extend LiquidJS and is available for use within Waypoint templates.
Currency
Use | currency
to format a number with a currency. Defaults to USD. Example:
Input
{{ 40.5 | currency }}
Output
$40.50
Currency codes and locales can be passed in as options to format a number to localized currency (defaults to ‘en-US’):
Input
{{ 10 | currency: 'EUR', 'fr-FR'}}
Output
10,00 €
Pluralize
Use | pluralize
to use a singular or plural version of a word based on a number.
Data
{ "user": { "followersCount": 1 }}
Input
{{user.followersCount}} {{ user.followersCount | pluralize: 'friend', 'friends' }}
Output
1 friend