Placeholders & functions
Placeholders let you inject the value of a field inside an e-mail message or inside the computed value of an auto field.
For instance, here's how you would use placeholders:
Dear {customer.name} {customer.lastname},
thank you for your order. The total amount is {total} and the order ID is {id}.
Best regards
In this example, the placeholders {customer.name}
and {customer.lastname}
will be replaced with the values of the name
and lastname
fields of the record referenced by the customer
field of the current record. The placeholder {total}
will be replaced with the value of the total
field of the current record, and the placeholder {id}
will be replaced with the ID of the current record.
Functions
Sometimes you need to transform the values before inserting them into your message. For example, you might want to make a string uppercase. It's easy: just type {name:upper}
. You can also chain multiple functions, as in {lastname:trim:upper}
(this one will remove whitespace from the value before converting it to upper case).
Functions to be used on text fields:
:lower
: returns the given string in lower case.:upper
: returns the given string in upper case.:substr(FROM)
or:substr(FROM, LEN)
: returns the substring starting from the given FROM char for the given LEN characters (or to the end of the string if not specified). For example:substr(2)
will remove the first two characters (0 is the first, 1 is the second).:trim
: removes whitespace from the beginning and the end of the string.:ifempty('VALUE')
: returns the input string if not empty, otherwise the given value. This can be used for setting defaults.:regexp_extract('REGEX')
: applies the given regular expression to the input value and returns the first capture. For example:regexp_extract('(..)$')
will return the last two chars.:regexp_replace('REGEX', 'REPLACE')
: looks for the given regular expression and applies the given replacement string. For example:regexp_replace(' ', '_')
replaces all spaces with underscores.:lpad(LEN, 'CHAR')
: left-pads the given string in order to make it at least LEN characters long by prepending the given character.:md5
: computes the MD5 of the given string (in hex representation).
Functions to be used on date/time fields:
:format('FORMAT')
: this function can be applied on date/time values and it lets you render them in the given format. For example:format('Y')
will just return the year. Valid format specifiers areY
,m
,d
,H
,i
,s
. This function will return a text value, so the above functions can be used.:add_days(NUM)
: adds the given number of days to the input date.:sub_days(NUM)
: subtracts the given number of days from the input date.:days_to(DATE)
: calculates the difference in days between the input date and the given one.
Do you need a function that is not implemented yet? Tell us ;-)