Liquid Filters
For the filters native to the Liquid language, please see the Liquid Filters Documentation.
Socotra also supports an extended set of Liquid filters, as described here. Some of the filters are only relevant for document production, others are relevant for calculations, and some apply to both.
Liquid Filters for Document Templates
format_number_currency
Formats a number as a currency appropriate to the specified region, including decimal and thousands separators. Inputs:
This evaluates to “€123.456,70”:
{{ 123456.7 | format_number_currency: "de","DE" }}
format_number
Formats a number based on the specified region, including decimal and thousands separators. Inputs:
This evaluates to “123,456.7”:
{{ 123456.7 | format_number: "en", "US" }}
format_number_pattern
Formats a number according to the specified pattern.
{{ vehicle_value | format_number_pattern: "0.0" }}
timestamp_millis_add
Add to a timestamp (timezone-aware).
{% assign new_timestamp = timestamp | timestamp_millis_add: "day", -1 %}
timestamp_millis_round_day_floor
Round a timestamp to the beginning of the day.
{% assign begin_of_today = "now" | get_timestamp_millis | timestamp_millis_round_day_floor %}
timestamp_millis_round_day_ceiling
Round a timestamp to the beginning of the next day.
{% assign begin_of_tomorrow = "now" | get_timestamp_millis | timestamp_millis_round_day_ceiling %}
lookup
Look up a value from a table in the /tables
folder within the product’s configuration.
{% assign rate = "my_rate_table" | lookup: my_lookup_key %}
The table must be a CSV file with only two columns, named key
and value
, lowercase. For example:
key,value Car,1 SUV,1.1 Motorcycle,2 Pickup,1.1
In the filter call, the name of the table and the key to look up both must be strings. Looking up 12
will not work, but "12"
will:
{% assign rate = "my_rate_table" | lookup: "12" %}
If a lookup fails (due to bad table name, bad key, or problem with your table) the return value will be undefined. In this case the will_not_be_defined
variable will not be defined at all:
{% assign will_not_be_defined = "example_table" | lookup: "bad key" %}
timestamp_millis_print
Format and display a timestamp using a given format date/time string.
{{ coverageStartTimestamp | timestamp_millis_print: "d MMM YYYY" }}
Multi-Use Filters
These filters are relevant to both document rendering and premium calculation:
Liquid Tips
Here are a few more suggestions for working with Liquid files.
Floating Point Assignments
When expressing decimal / float numbers, use a leading 0: 0.7
rather than .7
. This will work as expected:
{% assign myVariable = 0.7 %}
This will not define your variable:
{% assign myVariable = .7 %}
Lookup Table Syntax
Values in lookup tables may be enclosed in quotes, or not. In the example below, the "SUV"
key will be read as SUV
:
key,value Car,1 "SUV",1.1 Motorcycle,2 Pickup,1.1
Note
Though the placement of tables in a config might suggest that tables are scoped at the product level, they are actually scoped at the tenant level. We recommend that each table have a unique name to avoid unexpected lookup results. One common technique is to preface each table with the product name.
Debugging Liquid Template Rendering Errors
To debug calculations of premiums, taxes, or fees, create a variable (
{% assign myVar = foo %}
) for any value you want to see and then you can print out all assigned variables using this API endpoint or this Python Script .To debug document creation, you can render variables or values document using
{{ value }}
.If you get an error like this:
Error rendering liquid template revision...
it might be because you used the wrong name to refer to one of your field values. For example, perhaps you usedselect_experience
but the field name was actuallyyears_of_experience
.Note that for calculations, specifying fractional values less than one requires a leading zero; for example, use
0.12
instead of.12
.