Treepl CMS Filters

These Liquid filters are specific to Treepl CMS and in addition to the standard Liquid filters.

String Filters

| titlecase

Converts each word in a string to Title Case (capital initial letter for each word).

{{ "This is my sentence" | titlecase }}
This Is My Sentence

Date Filters

| date

Converts a timestamp into another date format. The format for this syntax is the same as strftime.

For example; if outputting the site's time using the "now" keyword, the default format is as below:

{{ "now" | date }}
27-Feb-2020

Or to reformat the date using 'strftime' syntax.

{{ "now" | date: "%Y-%m-%d %H:%M" }}
2019-09-19 17:48

date also works on strings if they contain well-formatted dates:

{{ "March 14, 2016" | date: "%b %d, %y" }}
Mar 14, 16

As well as the date filter being able to recogonize well formatted dates, it will also format 'seconds since 1970' back into a date.

For example; we have calculated a difference between today's date and 14 days ago in seconds (1209600) and now want to display that result as a true date:

{% assign dateDiff = "27-Feb-2020" | date: "%s" | minus: 1209600 %}
{{ dateDiff | date: "%v %r" }}
Thursday, February 13, 2020 12:00:00 AM

| datetime

Add the time component to the site's date:

{{ "now" | datetime }}
27-Feb-2020 4:46 AM

| date_utc

Converts a date to UTC (assuming that the date is always given in the site’s timezone)

{{ "now" | date_utc }}
2020-02-27 10:46:21Z

| date_add

Filters a given date time object (or a string convertible to a date time object) and adds (or subtracts) an amount from a defined date part based on the additional arguments passed, for example:

{% assign myDate = "2016-06-15T12:30:30.400" %}
{{ myDate | date_add: 7, "day" }}
2016-06-22 12:30:30Z

The first argument is the amount - an integer/number or a string convertible to an integer/number representing the amount of date or time units to add (if positive) or to subtract (if negative) from the input date time object

The second argument is the datePart - a string representing the date or time parts to be added or subtracted.
The possible values are:

  • "year"
  • "month"
  • "day"
  • "hour"
  • "minute"
  • "second"
  • "millisecond"

If one of the arguments is of an incompatible type or value, the filter will not alter the input.

Currency Filters

| domain_number_format

Formats a number to a string based on standard cultural number formating from the 'Currency and Format' settings of the current domain (void of any currency related attributes).

If liquid parsing is outside of the domain scope it uses the default domain settings, else the value is not changed.

For example, if the item price is set as 49990.9455 and the current domain is configured for United States:

{{ this.Price | domain_number_format }}
49,990.95

| set_number_format

Formats a number to a string based on standard cultural number formating from the 'Currency and Format' settings of the specified domain (void of any currency related attributes).
The domain settings to use are specified via the additional argument provided with the filter, which is the system ID for the 'Currency and Format' item saved against the required domain.

If liquid parsing is outside of the domain scope it uses the default domain settings, else the value is not changed.

For example, if the item price is set as 49990.9455 and the required domain is configured for Denmark:

{{ this.Price | set_number_format: "[formatSettingID]" }}
49.990,95

| domain_money_format

Formats a number to a string based on standard cultural monetary formating from the 'Currency and Format' settings of the current domain.

If liquid parsing is outside of the domain scope it uses the default domain settings, else the value is not changed.

For example, if the item price is set as 49990.9455 and the current domain is configured for United States:

{{ this.Price | domain_money_format }}
$49,990.95

| set_money_format

Formats a number to a string based on standard cultural monetary formating from the 'Currency and Format' settings of the specified domain.
The domain settings to use are specified via the additional argument provided with the filter, which is the system ID for the 'Currency and Format' item saved against the required domain.

If liquid parsing is outside of the domain scope it uses the default domain settings, else the value is not changed.

For example, if the item price is set as 49990.9455 and the required domain is configured for Denmark:

{{ this.Price | set_money_format: "[formatSettingID]" }}
49.990,95 $


Related Articles

External Resources

  • Liquid Date Formatting
    While there are some date formatting examples in the Liquid documentation here, a very useful tool for generating date formats can be found at STRFTIME.net

Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.


Questions?

We are always happy to help with any questions you may have.
Send us a message at support@treepl.co and we will consult you as soon as possible.