Using Functions in Templates

Proof Factor templates support mustache templates and lets you adjust the look and feel of specific notification variables (first_name, city, etc) and even add fallbacks using functions

You can add functions into templates by using pipes ("|"), then space, then the function name or a "||".

Check out examples of supported functions...

----------

Number

{{ variable | number }} 

If a number is more than 3 digits, it gets formatted with commas.

10122 visitors are on your site right now --> 10,122 visitors are on your site right now

----------

Casing

{{ variable | propercase }}  --> Test

{{ variable | downcase }}  --> test

{{ variable | upcase }}  --> TEST

If you get variable names that may not be formatted with the right case, use the case variable to standardize it. Especially helpful for name variables where users input the name themselves. 

{{ first_name | propercase }} 

Example:

JASon --> Jason

----------

Replace

{{ variable | replace[Devil's Canyon Cup from the Devil's Canyon Brewing Company, Canyon Cup] }}

In scenarios where you have a standard variable that is being sent that you want to replace in all cases, you'd use Replace. This is helpful when the variable is something like text that is too long or complicated, and you want to replace it with something shorter/easier.

To use it add the "replace" function, followed by two "arguments" inside [ ] brackets.

The first argument is the value to be replaced, and the second argument is the new value to replace it with.

 Before:

Jason bought the Devil's Canyon Cup from the Devil's Canyon Brewing Company in the last hour

After:

Jason bought the Canyon Cup in the last hour

----------

Delete

{{ title | delete [,] }} 

If there are specific characters that you want to ignore, you can call them out to remove them. This works well for scenarios where small characters (like periods, commas, etc) impede readability. 

For example, if your {{ title }} value is "Large, Pants" you can remove the comma.

Before:

Jon bought Large, Pants 10 minutes ago

After:

Jon bought Large Pants 10 minutes ago

You can further customize by deleting just one instance of a character in cases where In case there are multiple instances

Ex: {{ title }} is "Some. random. example. with periods"

{{ title | delete_first [.] }}  => "Some random. example. with periods"
{{ title | delete_last [.] }}  => "Some. random. example with periods"

----------

Truncation

{{ variable | truncate }} 

This reduces the variable's length to 30 characters.

Before:

The quick dog jumps over the lazy brown fox before running around and around the field as the fox watched on.

After:

The quick dog jumps over the...

You can further specify the exact length by adding a param to represent the number of characters

{{ variable | truncate 15 }} 

Before:

The quick dog jumps over the lazy brown fox before running around and around the field as the fox watched on.

After:

The quick dog ju...

----------

First

{{ variable | first_letter }}

Just like truncate, but it leaves just the first character of the variable. If you want to show just first initial, or customer initials or similar, this is what you use. This reduces the variable to the first character. Similar to truncate, but easier for display names as initials and such. 

Before:

James


After:

J

----------

Trimming

{{ title_with_link | delete_after[ - ] }} 

OR

{{ title_with_link | delete_before[ | ] }} 

Used when variable lengths are unpredictable, and Turncate doesn't give you enough flexibility, you may be able to use delete to delete whole character blocks before and after defined characters.

{{ title_with_link | delete_after[ - ] }}:

"Case of 6 Wine Glasses - Unlimited Returns and Fast Shipping!"

After:

"Case of 6 Wine Glasses"

OR

delete_before

{{ title_with_link | delete_before[ | ] }}:

"Last Chance - Case of 6 Wine Glasses"

After:

"Case of 6 Wine Glasses"

To use the trim_before and trim_after functions, put unwanted character "delimiter" inside [ ] brackets, following the function name and a space.

----------

Default Fallbacks

{{ variable | fallback[fallback word] }} 

When data is incomplete, you can have a fallback to cover. 

{{ first_name | fallback[A new customer] }} --> "A new customer" if first_name is blank

----------

Random Fallbacks

{{ variable | fallback_random[A marketer,Someone great] }}

Same as fallback, but to give your notifications more variety so that they don't get stale to visitors.

You can add fallback_random  function on multiple variables at once. Separate options via commas

{{ first_name | fallback_random[A new customer, a new sign-up, a new user, a new social proofer] }}

----------


Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽


Help by drift