Using Filters in Templates

Fomo templates contain sentence structures and merge tags.

They also support something we call filters. This lets you adjust the look and feel of specific notification variables (first_name, city, etc) with a little bit of "syntactical sugar."

Filters are included in your templates by simply adding a "|" (pipe), then a space, then the filter name. Note: you must use a single space between the elements (variable, filter, pipe) for this to work.

Here are a few of our currently supported filters...

Number

{{ variable | number }}

This formats numbers as comma-separated, if more than 3 digits long.

Example:

1,234 visitors are looking at this right now

Truncation

{{ variable | truncate }}

This trims the variable's value to 30 characters, by default. Example:

Hello, World. My name is Berna...

{{ variable | truncate 15 }}

The '15' parameter represents a custom character length of 15 characters. Example:

Hello, World. My name is B...

Colors

{{ variable | color #00f }}
{{ variable | color #0000ff }}

Color codes support 3 or 6 digit hexcodes, and will modify that variable's value only.

Default Fallbacks

{{ variable | default [some word] }}

After a variable, space, pipe, and another space, input "default" and then your fallback word(s) inside square brackets.

Example:

{{ first_name | default [Someone] }} --> "Someone" (if first_name is blank)

Bold

{{ variable | bold }} --> Hello, world

Self explanatory. This will bold the variable's value in your notification message.

Casing

Suppose your merge variable 'first_name' is "chRis."

{{ variable | propercase }} --> Chris

{{ variable | upcase }} --> CHRIS

{{ variable | downcase }} --> chris

Limitations:

  • The {{ time_ago }} does not support filters (yet)

  • Only one filter is allowed per variable. For example, this will not work: {{ variable | bold | upcase }}

If you have any questions abouut using filters in your notifications, let us know.