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

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.

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.

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 any 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".

Token | Output | |
---|---|---|

Month | `M` |
1 2 ... 11 12 |

`Mo` |
1st 2nd ... 11th 12th | |

`MM` |
01 02 ... 11 12 | |

`MMM` |
Jan Feb ... Nov Dec | |

`MMMM` |
January February ... November December | |

Quarter | `Q` |
1 2 3 4 |

`Qo` |
1st 2nd 3rd 4th | |

Day of Month | `D` |
1 2 ... 30 31 |

`Do` |
1st 2nd ... 30th 31st | |

`DD` |
01 02 ... 30 31 | |

Day of Year | `DDD` |
1 2 ... 364 365 |

`DDDo` |
1st 2nd ... 364th 365th | |

`DDDD` |
001 002 ... 364 365 | |

Day of Week | `d` |
0 1 ... 5 6 |

`do` |
0th 1st ... 5th 6th | |

`dd` |
Su Mo ... Fr Sa | |

`ddd` |
Sun Mon ... Fri Sat | |

`dddd` |
Sunday Monday ... Friday Saturday | |

Day of Week (Locale) | `e` |
0 1 ... 5 6 |

Day of Week (ISO) | `E` |
1 2 ... 6 7 |

Week of Year | `w` |
1 2 ... 52 53 |

`wo` |
1st 2nd ... 52nd 53rd | |

`ww` |
01 02 ... 52 53 | |

Week of Year (ISO) | `W` |
1 2 ... 52 53 |

`Wo` |
1st 2nd ... 52nd 53rd | |

`WW` |
01 02 ... 52 53 | |

Year | `YY` |
70 71 ... 29 30 |

`YYYY` |
1970 1971 ... 2029 2030 | |

`Y` |
1970 1971 ... 9999 +10000 +10001 Note: This complies with the ISO 8601 standard for dates past the year 9999 | |

Week Year | `gg` |
70 71 ... 29 30 |

`gggg` |
1970 1971 ... 2029 2030 | |

Week Year (ISO) | `GG` |
70 71 ... 29 30 |

`GGGG` |
1970 1971 ... 2029 2030 | |

AM/PM | `A` |
AM PM |

`a` |
am pm | |

Hour | `H` |
0 1 ... 22 23 |

`HH` |
00 01 ... 22 23 | |

`h` |
1 2 ... 11 12 | |

`hh` |
01 02 ... 11 12 | |

`k` |
1 2 ... 23 24 | |

`kk` |
01 02 ... 23 24 | |

Minute | `m` |
0 1 ... 58 59 |

`mm` |
00 01 ... 58 59 | |

Second | `s` |
0 1 ... 58 59 |

`ss` |
00 01 ... 58 59 | |

Fractional Second | `S` |
0 1 ... 8 9 |

`SS` |
00 01 ... 98 99 | |

`SSS` |
000 001 ... 998 999 | |

`SSSS ... SSSSSSSSS` |
000[0..] 001[0..] ... 998[0..] 999[0..] | |

Time Zone | `z` or `zz` |
EST CST ... MST PST (requires use of the `timezone` option) |

`Z` |
-07:00 -06:00 ... +06:00 +07:00 | |

`ZZ` |
-0700 -0600 ... +0600 +0700 | |

Unix Timestamp | `X` |
1360013296 |

Unix Millisecond Timestamp | `x` |
1360013296123 |

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 string | Output | |
---|---|---|

Time | `LT` |
8:30 PM |

Time with seconds | `LTS` |
8:30:25 PM |

Month numeral, day of month, year | `L` |
09/04/1986 |

`l` |
9/4/1986 | |

Month name, day of month, year | `LL` |
September 4, 1986 |

`ll` |
Sep 4, 1986 | |

Month name, day of month, year, time | `LLL` |
September 4, 1986 8:30 PM |

`lll` |
Sep 4, 1986 8:30 PM | |

Month name, day of month, day of week, year, time | `LLLL` |
Thursday, September 4, 1986 8:30 PM |

`llll` |
Thu, Sep 4, 1986 8:30 PM |

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:

Number | Format | String |
---|---|---|

10000 | `0,0.0000` |
10,000.0000 |

10000.23 | `0,0` |
10,000 |

10000.23 | `+0,0` |
+10,000 |

-10000 | `0,0.0` |
-10,000.0 |

10000.1234 | `0.000` |
10000.123 |

100.1234 | `00000` |
00100 |

1000.1234 | `000000,0` |
001,000 |

10 | `000.00` |
010.00 |

10000.1234 | `0[.]00000` |
10000.12340 |

-10000 | `(0,0.0000)` |
(10,000.0000) |

-0.23 | `.00` |
-.23 |

-0.23 | `(.00)` |
(.23) |

0.23 | `0.00000` |
0.23000 |

0.23 | `0.0[0000]` |
0.23 |

1230974 | `0.0a` |
1.2m |

1460 | `0 a` |
1 k |

-104000 | `0a` |
-104k |

1 | `0o` |
1st |

100 | `0o` |
100th |

1000.234 | `$0,0.00` |
$1,000.23 |

1000.2 | `0,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'.

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:

Operator | Associativity | Description |
---|---|---|

(...) | None | Grouping |

f(), x.y | Left | Function call, property access |

! | Left | Factorial |

^ | Right | Exponentiation |

+, -, not, sqrt, etc. | Right | Unary prefix operators (see below for the full list) |

*, /, % | Left | Multiplication, division, remainder |

+, -, || | Left | Addition, subtraction, concatenation |

==, !=, >=, <=, >, <, in | Left | Equals, not equals, etc. "in" means "is the left operand included in the right array operand?" (disabled by default) |

and | Left | Logical AND |

or | Left | Logical OR |

x ? y : z | Right | Ternary conditional (if x then y else z) |

There are also several pre-defined functions:

Function | Description |
---|---|

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 "gradeschool 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 |

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.

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.

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 of 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`