Skip to main content
LeadConduit supports combining, formatting, hashing, and performing math on values using template markup. Templating in LeadConduit is based on the popular Handlebars semantic templating library. A template is a string which contains any number of variable placeholders

Template Variable

Variable placeholders in templates start and end with two curly-brace characters: {{ lead.first_name }}. Multiple placeholders can be combined in a single template: {{ lead.first_name }} {{ lead.last_name }}. The universe of possible variables available to a template depends on the fields defined in your flow and the steps you’ve added to your flow.

Variable Formatting

LeadConduit has a built-in helper for formatting numbers and dates. Formatting a value is done with the format helper. If the value is a date field, then you may use date formatting options with the helper. If it’s a number field, then you may use the number formatting options with the helper.

Date Variable Formatting

To format a date, use the format helper: {{ format lead.dob format="YYYY-MM-DD" }} results in ‘2015-06-24’. The format option is a string which defines the format of the date. This format can be any combination of the below tokens. To escape characters in format strings, you can wrap the characters in square brackets: {{ format lead.dob format="[It's] MMMM Do" }} results in “It’s October 12th”.

Date Format Tokens

TokenOutput
MonthM1 2 … 11 12
Mo1st 2nd … 11th 12th
MM01 02 … 11 12
MMMJan Feb … Nov Dec
MMMMJanuary February … November December
QuarterQ1 2 3 4
Qo1st 2nd 3rd 4th
Day of MonthD1 2 … 30 31
Do1st 2nd … 30th 31st
DD01 02 … 30 31
Day of YearDDD1 2 … 364 365
DDDo1st 2nd … 364th 365th
DDDD001 002 … 364 365
Day of Weekd0 1 … 5 6
do0th 1st … 5th 6th
ddSu Mo … Fr Sa
dddSun Mon … Fri Sat
ddddSunday Monday … Friday Saturday
Day of Week (Locale)e0 1 … 5 6
Day of Week (ISO)E1 2 … 6 7
Week of Yearw1 2 … 52 53
wo1st 2nd … 52nd 53rd
ww01 02 … 52 53
Week of Year (ISO)W1 2 … 52 53
Wo1st 2nd … 52nd 53rd
WW01 02 … 52 53
YearYY70 71 … 29 30
YYYY1970 1971 … 2029 2030
Y1970 1971 … 9999 +10000 +10001 Note: This complies with the ISO 8601 standard for dates past the year 9999
Week Yeargg70 71 … 29 30
gggg1970 1971 … 2029 2030
Week Year (ISO)GG70 71 … 29 30
GGGG1970 1971 … 2029 2030
AM/PMAAM PM
aam pm
HourH0 1 … 22 23
HH00 01 … 22 23
h1 2 … 11 12
hh01 02 … 11 12
k1 2 … 23 24
kk01 02 … 23 24
Minutem0 1 … 58 59
mm00 01 … 58 59
Seconds0 1 … 58 59
ss00 01 … 58 59
Fractional SecondS0 1 … 8 9
SS00 01 … 98 99
SSS000 001 … 998 999
SSSS ... SSSSSSSSS000[0..] 001[0..] … 998[0..] 999[0..]
Time Zonez or zzEST CST … MST PST (requires use of the timezone option)
Z-07:00 -06:00 … +06:00 +07:00
ZZ-0700 -0600 … +0600 +0700
Unix TimestampX1360013296
Unix Millisecond Timestampx1360013296123

Localized Date Formats

Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale. There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart. To change the locale, use the locale options: {{ format date format="LLL" locale="fr" }} results in “24 june 2015 17:24”.
Format stringOutput
TimeLT8:30 PM
Time with secondsLTS8:30:25 PM
Month numeral, day of month, yearL09/04/1986
l9/4/1986
Month name, day of month, yearLLSeptember 4, 1986
llSep 4, 1986
Month name, day of month, year, timeLLLSeptember 4, 1986 8:30 PM
lllSep 4, 1986 8:30 PM
Month name, day of month, day of week, year, timeLLLLThursday, September 4, 1986 8:30 PM
llllThu, Sep 4, 1986 8:30 PM

Number Variable Formatting

To format a number, use the format helper: {{ format lead.mortgage.first_mortgage_balance format="$0,0.00"}} results in ‘$45,302.00’. The format option is a string which defines the format of the number. See the table of examples below:
NumberFormatString
100000,0.000010,000.0000
10000.230,010,000
10000.23+0,0+10,000
-100000,0.0-10,000.0
10000.12340.00010000.123
100.12340000000100
1000.1234000000,0001,000
10000.00010.00
10000.12340[.]0000010000.12340
-10000(0,0.0000)(10,000.0000)
-0.23.00-.23
-0.23(.00)(.23)
0.230.000000.23000
0.230.0[0000]0.23
12309740.0a1.2m
14600 a1 k
-1040000a-104k
10o1st
1000o100th
1000.234$0,0.00$1,000.23
1000.20,0[.]00 $1,000.20 $
1001$ 0,0[.]00$ 1,001
-1000.234($0,0)($1,000)
-1000.234$0.00-$1000.23
1230974($ 0.00 a)$ 1.23 m
Use the locale option to format the number to a particular locale: {{ format lead.mortgage.first_mortgage_balance locale="fr" format="$0,0.00" }} results in ‘€45 302.00’.

Converting Number and Boolean to String

Fields of type number and boolean can be converted to string using the format helper with the dataType="String" option: {{format field_name dataType="String"}} Example:
  • Input: {{format lead.age dataType="String"}} with lead.age = 30
  • Output: “30”

Converting String to Number

Fields whose final result from the format helper is a string can be converted to a number if the dataType="Number" option is passed and the value is a string representing a valid number. Examples:
  • Input: {{format lead.postal_code dataType="Number"}} with lead.postal_code = ‘78751’
  • Output: 78751 (as a number value)
If the string does not represent a valid number, the result will not be converted:
  • Input: {{format lead.postal_code dataType="Number"}} with lead.postal_code = ‘H3Z 2Y7’
  • Output: ‘H3Z 2Y7’
This can also be used with dates if the formatting returns only numbers, such as epoch time:
  • Input: {{format lead.source_timestamp format="X" dataType="Number"}} with lead.source_timestamp = ‘2015-06-24T17:24:49.060Z’
  • Output: 1435166689 (as a number value)

Variable String Manipulation

Strings can be manipulated with the following helpers:

Lowercase

Transforms the value to lowercase: {{lowercase field_name}} Example:
  • Input: {{lowercase lead.first_name}} with lead.first_name = “Mike”
  • Output: “mike”

Uppercase

Transforms the value to uppercase: {{uppercase field_name}} Example:
  • Input: {{uppercase lead.first_name}} with lead.first_name = “Mike”
  • Output: “MIKE”

Substring

Returns a substring from the start position to the end position, or from the start position to the end of the string if no end position is provided: {{substring field_name start="3"}} Example:
  • Input: {{substring lead.first_name start="3"}} with lead.first_name = “Michael”
  • Output: “chael”
{{substring field_name start="2" end="4"}} Example:
  • Input: {{substring lead.first_name start="2" end="4"}} with lead.first_name = “Michael”
  • Output: “ich”

Replace

Replaces the pattern with the content of the replace option. The pattern can be a literal string or a regular expression using the regexp() option: {{replace field_name pattern="Mi" replace="At"}} Example:
  • Input: {{replace lead.first_name pattern="Mi" replace="At"}} with lead.first_name = “Michael”
  • Output: “Atchael”
{{replace field_name pattern="regexp(h.{3})" replace="ke"}} Example:
  • Input: {{replace lead.first_name pattern="regexp(h.{3})" replace="ke"}} with lead.first_name = “Michael”
  • Output: “Micke”

Extract

Extracts all occurrences found with the regular expression in the pattern: {{extract field_name pattern="\$begin:math:display$(.*?)\\$end:math:display$"}} Example:
  • Input: {{ extract foo pattern="(?\<=#)(\\w+)(?=#)" }} with lead.first_name = “#John#Doe#Smith”
  • Output: “John Doe”

Variable Math

To perform math operations, use the math helper: {{ math "1 + 1" }} results in 2. Of course, variables can also be used: {{ math "1 + lead.random_number" }} might result in 32 depending on the value of lead.random_number. The math expression accepts a pretty basic grammar. Operators have the normal precedence:
OperatorAssociativityDescription
(…)NoneGrouping
f(), x.yLeftFunction call, property access
!LeftFactorial
^RightExponentiation
+, -, not, sqrt, etc.RightUnary prefix operators (see below for the full list)
*, /, %LeftMultiplication, division, remainder
+, -, ||LeftAddition, subtraction, concatenation
==, !=, >=, <=, >, <, inLeftEquals, not equals, etc. “in” means “is the left operand included in the right array operand?” (disabled by default)
andLeftLogical AND
orLeftLogical OR
x ? y : zRightTernary conditional (if x then y else z)
There are also several pre-defined functions:
FunctionDescription
sin(x)Sine of x (x is in radians)
cos(x)Cosine of x (x is in radians)
tan(x)Tangent of x (x is… well, you know)
asin(x)Arc sine of x (in radians)
acos(x)Arc cosine of x (in radians)
atan(x)Arc tangent of x (in radians)
sqrt(x)Square root of x. Result is NaN (Not a Number) if x is negative.
log(x)Natural logarithm of x (not base-10). It’s log instead of ln because that’s what JavaScript calls it.
abs(x)Absolute value (magnitude) of x
ceil(x)Ceiling of x — the smallest integer that’s >= x.
floor(x)Floor of x — the largest integer that’s <= x
round(x)X, rounded to the nearest integer, using “grade-school rounding”
roundTo(x, n)Rounds x to n places after the decimal point
exp(x)ex (exponential/antilogarithm function with base e)
random(n)Get a random number in the range [0, n). If n is zero, or not provided, it defaults to 1.
fac(n)n! (factorial of n: “n * (n-1) * (n-2) * … * 2 * 1″)
min(a,b,…)Get the smallest (“minimum”) number in the list
max(a,b,…)Get the largest (“maximum”) number in the list
pyt(a, b)Pythagorean function, i.e. the c in “c2 = a2 + b2“
pow(x, y)xy. This is exactly the same as “x^y”. It’s just provided since it’s in the Math object from JavaScript
atan2(y, x)arc tangent of x/y. i.e. the angle between (0, 0) and (x, y) in radians
if(c, a, b)Function form of c ? a : b

Example

To calculate the loan-to-value ratio, given a mortgage loan amount and the value of the home: {{ math "(lead.mortgage.loan.amount / lead.mortgage.new_property_value) * 100" }}%. Note that this example expresses the LTV as a percentage, first by calculating the percentage and then by appending the % character outside the variable placeholder. This could instead be handled using formatting.

Variable Math Formatting

The math helper supports the same options as the format helper for numbers: format and locale. For example, to calculate the loan-to-value ratio and format it as a percentage: {{ math "lead.mortgage.loan.amount / lead.mortgage.new_property_value" format="0.[00]%" }}. This would return the LTV percentage with up to 2 decimal points (i.e. 72.93%) as a string value.

Variable Hashing

LeadConduit supports a wide variety of hashing functions that can be applied to variables in a template. The helper name determines the hashing algorithm. For example, to use MD5 to hash the email address use: {{ md5 lead.email }}. All the following hashing algorithms are supported:
  • md4
  • md5
  • ripemd
  • ripemd160
  • sha1
  • sha224
  • sha256
  • sha384
  • sha512
  • whirlpool
Multiple values can be hashed together: {{ md5 lead.email lead.phone_1 }}. This can be used to salt the hash also: {{ md5 lead.email "this is my salt" }}. The salt option can also be used. This is the equivalent of the last example: {{ md5 lead.email salt="this is my salt" }}. Hashing supports multiple encodings using the encoding option: {{ md5 lead.email encoding="base64" }} results in something like “tkK0IXs0sejTvZFfxlxEUg==”. The following encodings are supported:
  • hex (default)
  • base64
  • latin1