Here, you will find step-by-step instructions and examples of how to use various tag types to complete specific tasks in your DOCX documents, such as calculating amounts using math functions or inserting files.
Merge tags formatting functions (date, number, currency)
You can format merge tags to show date, number, or currency values.
Note: Be sure to only use ‘these’ quotation marks for strings.
dateFormat(DateFieldName, current_date_format, required_date_format)
{{dateFormat(Date1, ‘yyyy-MM-dd’, ‘yyyy-dd-MM’)}} | “2023-22-02” |
{{dateFormat(Date2, ‘yyyy-MM-dd’, ‘EEE, d MMM yyyy’)}} | Wed, 22 Feb 2023 |
Use the {{$today}} function to insert a non-editable date.
numFormat(FieldName, string_format) – accepts a numeric value and a string with a pattern for formatting.
numFormat(FieldName, string_format , groupseparator_symbol, decimalseparator_symbol) is also acceptable.
{{numFormat(Field1, ‘###,###.00’)}} | 16,326.20 | “‘###,###.00’ adds zeros if an expression has fewer symbols after a comma than is required.” |
{{numFormat(Field2, ‘###,###.##’)}} | 16,326.23 | ‘###,###.##’ rounds the expression to two symbols after a comma if the number has more. |
{{numFormat(Field3, ‘$###,###.00’)}} | $16,326.20 | Adds currency symbol before the number. |
Use Tag Generator to see other available date and number formats.
Table with a dynamic number of rows
The following is an example of a simple table with headers:
Name | Quantity |
{{table(Products)}} |
|
{{Name}} | {{Quantity}} |
{{endtable}} |
|
Show or hide tables, rows, and columns
Conditional tags control which parts of a table appear in the generated document. Each tag holds a condition. When the condition is true, the element stays. When it's false, the element is removed from the document.
Tag | Controls | Where to place it |
{{tableIf(condition)}} | The entire table | In its own row at the top of the table |
{{rowIf(condition)}} | A single row | In the first cell of the row |
{{columnIf(condition)}} | A single column | In a cell of the column, usually the header cell |
Write the condition for the case where you want the element to stay. To hide an element when a flag is true, reverse the condition with ! — {{columnIf(!switcher)}}.
Write a condition
The expression inside the parentheses is evaluated against the data you supply:
A variable or field: {{rowIf(isActive)}}
A comparison with ==, !=, <, >, <=, or >=: {{columnIf(total > 0)}}
Several conditions joined with && or ||: {{tableIf(showSection && hasItems)}}
A boolean field maps directly. {{columnIf(switcher)}} keeps the column when switcher is true and removes it when switcher is false.
Show or hide an entire table
Place {{tableIf(condition)}} in its own row at the top of the table, above the table content. In a data-driven table, place it above the {{table(...)}} loop tag.
{{tableIf(showSummary)}} |
|
Metric | Value |
Revenue | {{revenue}} |
When showSummary is false, the entire table is removed from the document.
In a data-driven table:
{{tableIf(items)}} |
|
{{table(items)}} |
|
Name | Qty |
{{name}} | {{qty}} |
{{endtable}} |
|
The table appears only when items contains at least one record.
Show or hide a single row
Place {{rowIf(condition)}} in the first cell of the row you want to control.
Inside a {{table(...)}} loop, the condition is evaluated for each iteration, so the tag keeps or drops each row individually:
Header |
|
{{table(people)}} |
|
{{rowIf(isActive)}} | {{name}} |
{{endtable}} |
|
Show or hide a single column
Place {{columnIf(condition)}} in a cell of the column you want to control, usually the header cell. When the condition is false, the cell is removed from every row, so the whole column disappears.
The column is identified by the position of the tag, not by name, so the tag has to sit inside the column it controls.
Tip: Put the column headers in the first row and the {{table(...)}} loop tag in the second row, so the {{columnIf}} tags stay attached to their header cells.
Column one | {{columnIf(showColumn)}} Column two | Column three |
{{table(items)}} |
|
|
{{Column1}} | {{Column2}} | {{Column3}} |
{{endtable}} |
|
|
When showColumn is false, the second column is removed from the header and from every data row.
You can control several columns independently:
{{columnIf(showA)}} A | {{columnIf(showB)}} B | {{columnIf(showC)}} C |
What to keep in mind
Conditional tags have no else. To swap one column or row for another, put complementary conditions on each — {{columnIf(switcher)}} on one and {{columnIf(!switcher)}} on the other.
All three tags work inside {{table(...)}} loops and nested tables. Conditions are evaluated against the data context of each iteration.
If removing rows or columns leaves a table empty, the empty table is removed automatically. To control headers and footers of empty tables, see Hide an empty table header/footer below.
Hide an empty table header/footer (using {{h}} tag)
If tables contain any tags below headers / above footers that should be automatically hidden (in case tables have no records), add an {{h}} tag before each row with headers/footers.
To automatically hide empty tables that don't contain at least one row of data (pre-filled from tags), refer to the syntax below:
{{table(Products)}} |
|
{{h}}Product List |
|
{{h}}Name | Quantity |
{{Name}} | {{Quantity}} |
{{endtable}} |
|
Calculate totals in a table column ($sumabove variable)
{{$sumabove}} displays the sum of numbers in cells above this tag.
{{table(Products)}} |
|
{{h}}Name | Quantity |
{{Name}} | {{Quantity}} |
{{h}}Total Quantity | {{$sumabove}} |
{{endtable}} |
|
It's possible to use the result from a {{$sumabove}} tag as a parameter in functions like {{numFormat($sumabove, ‘$###,###.00’}}
Insert images and files ({{imageFile}} tag)
Use the {{imageFile}} tag to insert images or attached files (PDF, DOCX) into the body of a generated document. The data is provided by a pre-fill bot — for example, a file attachment from a Salesforce record or an image field from your data source.
The tag is typically used inside a {{for}} loop when the source field can hold more than one file:
{{for(Attachments)}}
{{imageFile(ImgField)}}
{{endfor}}
Default behaviour
By default, {{imageFile(ImgField)}} renders the image at its native size, with no dimension control. This means:
Logos and other high-resolution images render full-size in headers and footers.
Body images that don't fit the remaining space on the current page are pushed to a new page, leaving a blank gap above them.
To avoid this, you can pass optional sizing parameters to the tag.
Sizing parameters
Tag | What it does |
{{imageFile(ImgField, w:200)}} | Fixed width of 200 pt. Height is derived from the original aspect ratio. |
{{imageFile(ImgField, h:60)}} | Fixed height of 60 pt. Width is derived from the original aspect ratio. |
{{imageFile(ImgField, w:200, h:60)}} | Image is fitted into a 200 × 60 bounding box, preserving aspect ratio. |
{{imageFile(ImgField, fit:page)}} | Image is scaled to fit the remaining vertical space on the current page. |
{{imageFile(ImgField)}} | Default — native size, no sizing applied (identical to the previous behaviour). |
Note: Values for w and h are in points (pt), the same unit used by the rest of the DOCX renderer.
Rules that always apply
Aspect ratio is never distorted — when you specify both w and h, the image is fitted inside the box rather than stretched to fill it.
Images are never upscaled — if the source image is smaller than the specified dimensions, it renders at its native size.
fit:page caps width to the page body width in addition to checking remaining vertical space, so an image cannot overflow the page margins.
Omitting all parameters produces the exact same output as before — full backward compatibility, no template migration needed.
How fit:page works
fit:page measures the vertical space remaining on the current output page when the tag is reached:
If the image fits that remaining space, it is rendered inline — no page break, no blank gap above it.
If it does not fit, the image is scaled down proportionally until it does.
This is the recommended setting for body images that are placed below other dynamic content (tables, conditional paragraphs, lists), because the available space cannot be known in advance.
Multi-page attachments (PDF/DOCX files)
When the source field contains a multi-page file (PDF or DOCX), each page of the source is rendered as a separate image, stacked vertically in the output. Sizing rules apply per page:
Sizing parameter | Behaviour for a multi-page file |
w:N | All pages stacked vertically; each page rendered at the fixed width, with height from aspect ratio. |
h:N | All pages stacked vertically; each page rendered at the fixed height, with width from aspect ratio. |
w:N, h:N | All pages stacked vertically; each page fitted to the bounding box. |
fit:page | Page 1 is fitted into the remaining space on the current output page; pages 2+ each start a new output page and render at full size. |
Examples
Fix the logo size in a header
{{imageFile(CompanyLogo, h:20)}}
Renders the logo at a fixed 20 pt height, scaled proportionally — no more giant logos when someone uploads a high-resolution PNG.
Make a body image fit the page automatically
{{imageFile(SiteDiagram, fit:page)}}
If the diagram fits in the space remaining on the current page, it renders inline. If not, it is shrunk to fit — no blank page break.
Constrain an image to a bounding box (signature, stamp)
{{imageFile(Signature, w:160, h:60)}}
The signature is fitted into a 160 × 60 box, preserving its aspect ratio.
Insert a list of attachments from a data source
{{for(Attachments)}}
{{imageFile(File, w:480)}}
{{endfor}}
Each attachment is rendered at a fixed 480 pt width. If an attachment is a multi-page PDF, every page is rendered at the same width, stacked vertically.
Conditional Logic
You can show or hide paragraphs of text depending on conditions. To create a condition, you can use a Field or Variable (for more complex cases) with operators such as =, !=, >, <. You can use set values, field values, or variables for condition values.
To show or hide entire tables, rows, or columns instead of paragraphs, see Show or hide tables, rows, and columns above.
The basic syntax of conditional tags is as follows:
{{if(condition)}} success action {{endif}}
{{if(condition)}} success action {{else}} fail action {{endif}}
Let's look at each piece separately:
{{if(condition1)}} success action, if condition 1 is true;
{{else(condition2)}} success action, if condition 2 is true;
{{endif}} condition is any expression, variable, or value from a function, calculation, or data source.
The example below demonstrates what the message will contain, depending on the account's city:
{{if(AccountCity=‘Boston’)}} Hello!
{{else(AccountCity=‘London’)}} God save the Queen!
{{else}} Season’s greetings! {{endif}}
Here is a summary report for your account:
{{$total=0}}
Opportunity Name | Opportunity Status | Opportunity Amount |
{{table(Opportunity)}} |
|
|
{{OpportunityName}} | {{OpportunityStatus}} | {{OpportunityAmount}} |
{{endtable}} |
| {{$sumabove}} {{$total=$sumabove}} |
{{if($total<50000)}} Happy new year!
{{else($total<100000)}} Happy new year! You are eligible for a massive discount.
{{endif}}
List
Use the For tag syntax to display a list of items. For example, a list of patient’s visits to the doctor:
Doctor’s name: {{DoctorFullName}}
{{for(Visits)}}
Patient’s name: {{PatientFullName}}
Date of visit: {{DateofVisit}}
{{endfor}}
To list all the doctors and then add a list of visits to each of them, use nested For tags:
{{for(Doctors)}}
Doctor’s name: {{DoctorFullName}}
{{for(Visits)}}
Patient’s name: {{PatientFullName}}
Date of visit: {{DateofVisit}}
{{endfor}}
{{endfor}}
Variables
{{$variableName = VariableValue}} creates a variable named variableName in the document environment and assigns it a value such as VariableValue.
If a variable named variableName already exists, its value is rewritten, and the VariableValue name is assigned. You won’t be able to reach the previous value of $variableName if it’s overwritten.
{{$var = 5.48}} | Assign variable $var value 5 |
{{$var = ‘Harry Potter’}} | Assign variable $var the string value ‘Harry Potter’ |
{{$var = OpportunityName}} | Assign variable $var the value from the data source |
{{$var = 5 + 47 / 2 - 34 * CompanyPrice}} | Assign variable $var the calculated value |
{{$var = true}} | Assign variable $var and assign it a boolean value true |
{{$var}} | Display value of $var |
{{$var > 47}} {{endsWith(OpportunityName, $var)}} | Example of using variables in calculations and functions |
Note: Be sure not to use the variable tags in the document’s footers or headers as they will be left empty and won’t be pre-filled with any data after generating documents.
Math functions
Here, you'll find a table with tags for calculating mathematical functions, along with examples of how they work:
* | Accepts numbers:
{{4 * 5}} {{sqrt(9) * sqrt(16)}} {{4 * (5 + 3)}} |
20 12 32 |
/ | Accepts numbers:
{{42 / 3}} {{(5 + 3) / (1 + 1)}} {{sum(3, 4, 5) / 4}} |
14 4 3 |
% | Accepts numbers. Divides the first parameter by second and returns the remainder:
{{42%2}} {{33 % 4}} {{34 % 4}} |
0 1 2 |
+ | Accepts two numbers or strings:
{{2 + 6 * 7}} {{4 + abs(-2)}} {{sqrt(17 + 8)}} {{‘Pineapple avenue, ’ + 56}} |
44 6 5 Pineapple avenue, 56 |
- | Accepts numbers: {{22 - 4}} {{17 * 3 - 8}} {{pow(6-3, 2)}} |
18 43 9 |
> | Accepts numbers, return booleans: {{5 > 7}} {{5 > 3}} {{16 > pow(3, 2)}} |
false true true |
>= | {{6 >= 4 + 2}} {{8 >= 4 +2}} | true true |
< | {{5 < 7}} {{5 < 4}} {{sqrt(25) < sqrt(4 * 9)}} | true false true |
<= | {{3 <= 1 + 2}} {{3 <= 4}} {{8 <= 7}} | true true false |
!= | Accepts any expression, returns false if expressions are equal
{{45 != 5 * 9}} {{‘Jack’ != ‘Jackson’}} {{2 < 5 != 16 < sqrt (49)}} |
false true true |
=,==
| Accepts any expression, returns true if expressions are equal
{{45 = 5 * 9}} {{‘Jack’ == ‘Jackson’}} {{2 < 5 == 16 < sqrt (49)}} {{‘Jack Jackson’ = ‘Jack ’ + ‘Jackson’}} |
true false false true |
The only accepted unary operation is boolean NOT, which consumes and reverts a boolean. Use the ! sign to perform this operation.
For example: !(2 > 5) will return true.
Numeric functions
abs(num_value) – returns the absolute value of a number.
Examples:
{{abs(-3.1438)}} will return 3.1438
{{abs(465.5)}} will return 465.5
ceil(num_value) – rounds number up to the closest whole number that is bigger, then passes one
Examples:
{{ceil(3.14)}} will return 4.
{{ceil(-3.14)}} will return -3.
{{ceil(2.99)}} will return 3
floor(num_value) – rounds number down to the closest whole number that is smaller than the passed one
Examples:
{{floor(3.14)}} will return 3.
{{floor(-3.14)}} will return -4.
{{floor(2.99)}} will return 2
round(num_value) – rounds number to closest whole number according to math rounding rules
Examples:
{{round(3.14)}} will return 3.
{{round(-3.5)}} will return -4.
{{round(2.99)}} will return 3
pow(num_base, num_power) – returns num_base to the power num_power
Examples:
{{pow(3, 2)}} will return 9
{{pow(8, 3)}} will return 512
random() – returns a decimal number between 0 and 1, including 0 and 1. Does not require parameters.
sqrt(num_value) – return the square root of num_value.
Examples:
{{sqrt(273.43)}} will return 16.5357
{{sqrt(64)}} will return 8
{{sqrt(-3)}} will return NaN (not a number).
{{sqrt(0)}} will return 0
{{sqrt(3.14 / 2)}} will return 1
String functions
map (object, [key, val], [default]) – accepts a list of objects. The first value object in the list is a value that will be compared to keys. After the object, the next values are split into key-value pairs. The object is compared to keys; if a key matches an object, that value will be returned. If any key does not match an object, then the number of parameters passed for mapping is odd, and nothing will be returned. If there is an even number of parameters, the last value is considered default and returned if no keys equal an object. To simplify understanding, the keys are underlined below.
Examples:
{{map(‘Y,' ‘R,' 'Red,' ‘O’, ‘Orange,' ‘Y,' ‘Yellow,' ‘B,' ‘Blue,' ‘G,' ‘Green,' ‘P,' ‘Purple,' ‘Black’)}} will return Yellow. In a document, you will write it simply as {{map(‘Y,' ‘R', 'Red', ‘O’, ‘Orange', 'Y’, 'Yellow’, 'B’, 'Blue', ‘G,' ‘Green', 'P', ‘Purple', 'Black’)}}
{{map(‘M’, ‘R', 'Red', ‘O’, ‘Orange’, ‘Y’, ‘Yellow’, ‘B’, ‘Blue’, ‘G', ‘Green', ‘P,' ‘Purple', ‘Black’)}} will return ‘Black’, because no key for ‘M’ was found, and as soon as ‘Black’ doesn’t have a corresponding value, it will be accepted as a default value. 14 arguments (including numbers) were passed for mapping.
{{map(‘M’, ‘R’, ‘Red’, ‘O’, ‘Orange’, ‘Y’, ‘Yellow’, ‘B’, ‘Blue’, ‘G’, ‘Green’, ‘P’, ‘Purple’)}} will not return anything, because there are no unmatched keys. The number of arguments is 13 (an odd number).
charAt(string_value, index) – return a letter, that is in string_value on the spot index. The count starts with 0. If the index is negative, fractional, larger, or equal, then string_value number of letters, an empty string will be returned. The result will be treated as a string value.
Examples:
{{charAt(‘Abcdefg’, 2)}} will return ‘c’
{{charAt(‘Abcdefg’, 0)}} will return ‘A’
{{charAt(‘Abcdefg’, 37)}} will not return anything.
contains(string_value, pattern) – returns true if string_value contains pattern. The function is case-sensitive.
Examples:
{{contains(‘Taste this piece of pie’, ‘is piec’)}} will return true
{{contains(‘Taste this piece of pie’, ‘taste’)}} will return false
endsWith(string_value, string_pattern) – a function that returns true or false value. Function will return true, if string_value ending matches string_pattern. The function is case-sensitive.
Examples:
{{endsWith(‘Dedalus Diggle’, ‘Diggle’)}} will return true.
{{endsWith(‘Dedalus Diggle’, ‘diggle’)}} will return false because ‘D’ is not equal to ‘d’
equalsIgnoreCase(string_value_1, string_value_2) – a function that returns true or false, depending on the equality ofstring_value_1 and string_value_2. Is case insensitive, meaning that it returns true if a lower case of string_value_1 is equal to the lower case of string_value_2
Examples:
{{equalsIgnoreCase(‘Bart Simpson’, ‘bart SIMPSON’)}} will return true because to lower case both strings will equal ‘bart simpson’.
{{equalsIgnoreCase(‘Rolling Stones’, ‘Roll that Stone’)}} will return false.
length(string_value) – returns the number of symbols in a string value.
Examples:
{{length(‘Abcde’)}} will return 5
{{length(‘’)}} will return 0
{{length(‘Annoying orange’)}} will return 15
replace(sting_variable, pattern1, pattern2) – finds all occurrences of pattern1 in sting_variable and replaces it withpattern2. If pattern1 is not found in the string, will return sting_variable.
Examples:
{{replace(‘JHMAB52EC8oo65o’,‘o’,‘0’)}} will return ‘JHMAB52EC800650’
{{replace(‘That’s what you get for waking up in Vegas’, ‘Vegas’, ‘New York’)}} will return ‘That’s what you get for waking up in New York’.
split(string_value, pattern, index). To perform this function, all pattern occurrences are found in string_value. A string is broken into a list of strings as if any pattern occurrence means the previous string ends and the next string starts after it. A piece with an index number in this list starting from zero will be returned. Nothing will be returned if an index exceeds the number of pieces in the list.
Examples:
{{split(‘To be or not to be?’, ‘ ’ , 5 )}} will be split by space into ‘To’, ‘be’, ‘or’, ‘not’, ‘to’ be?’; starting from 0 the piece of string, that has index 5 will be ‘be?’, so ‘be?’ will be returned.
{{split(‘John|Mathews|47|Approved’ , ’|’ , 1)}} will return ‘Mathews’
startsWith(string_value, string_pattern) – a function that returns a true or false value. The function will return true ifstring_value beginning matches string_pattern. The function is case-sensitive.
Examples:
{{startsWith(‘Meet me in London’, ‘Meet’)}} will return true.
{{startsWith(‘Meet me in London’, ‘meet’)}} will return false because ‘M’ is not equal to ‘m’.
substring(string_value, start), substring(string_value, start, end) – returns a piece of string. If two arguments are passed, then the ending of a string starts from the start index. In case of three arguments, a piece of string_value starting from the start symbol to the end symbol will be returned. Letter with index end will not be included. The first letter has an index of 0.
Examples:
{{substring(‘0123456’ , 2 , 5)}} will return ‘234’.
{{substring(‘0123456’ , 3)}} will return ‘3456’.
titleCase(string_value) – will return string_value with all first letters to uppercase.
Examples:
{{titleCase(‘When in Rome, do as the Romans’)}} will return “When In Rome, Do As The Romans”.
{{titleCase(‘When the going gets tough, the tough get going’)}} will return “When The Going Gets Tough, The Tough Get Going”
toLowerCase(string_value) – will return string_value with all first letters to uppercase.
Examples:
{{toLowerCase(‘When iN Rome, dO as tHe RomAns’)}} will return “when in rome, do as the romans”.
{{toLowerCase(‘WhEn thE goiNg getS toUGh, the tOUgh get goINg’)}} will return “when the going gets tough, the tough get going”
toUpperCase(string_value) – will return string_value with all first letters to uppercase.
Examples:
{{toUpperCase(‘When iN Rome, dO as tHe RomAns’)}} will return “WHEN IN ROME,DO AS THE ROMANS”.
{{toUpperCase(‘WhEn thE goiNg getS toUGh, the tOUgh get goINg’)}} will return “WHEN THE GOING GETS TOUGH, THE TOUGH GET GOING”
toUpperCaseFirst(string_value) – will return string_value with the first letter capitalized.
Examples:
{{toUpperCaseFirst(as of March 05, 2024)}} will return “As of March 05, 2024”
trim(string_value) removes spaces in the beginning and in the end of a string
Examples:
{{trim(‘ 12CVCV123-454 ’)}} will return “12CVCV123-454”.
Fillable fields
In most cases, it is recommended that you use the Fields panel to drag and drop fillable fields into your document. However, if needed, you can also add fillable fields using the fillable field tag syntax.
Examples:
Text field: {{t:t;r:n;l:"text_field _1";}}
Signature: {{t:s;r:n;l:"signature_field _1";}}
Initials: {{t:i;r:n;l:"initials_field _1";w:200;}}
Dropdown: {{t:d;r:n;l:"Dd_field _1";dd:first option,second option,third option;w:200;}}
Checkbox: {{t:c;r:n;l:"checkbox_field _1";}}
Date: {{t:dt;r:n;l:"date_field _1";w:150;p:"DD/MM/YYYY";}}
The table below shows the most widely used fillable field tags in Document Generation and the types of fields to which they can be applied.
KEY | What does it mean? | Accepted format & values |
|
t | TYPE of the field | s (for signature) i (for initials) t (for text) d (for dropdown) c (for checkboxes) dt or date (for dates) |
|
r | REQUIRED | y (for required) n (for optional) |
|
l | LABEL | “Field name” |
|
dd | DROPDOWN | "option1, option2, option3, ...." |
|
w | WIDTH | w (width) |
|
h | HEIGHT | h (height) |
|
p | DATE FORMAT | MM/DD/YYYY | 09/13/2024 |
DD/MM/YYYY | 13/09/2024 |
|
|
HH:mm | 02:30 |
|
|
MMM DD, YYYY | Sep 13, 2024 |
|
|
MM/DD/YY | 09/13/24 |
|
|
YYYY-MM-DD | 2024-09-13 |
|
|
YYYY/MM/DD | 2024/09/13 |
|
|
YYYY-M-D | 2024-9-13 |
|
|
YYYY/M/D | 2024/9/13 |
|
|
D.M.YYYY | 13.9.2024 |
|
|
D-M-YYYY | 13-9-2024 |
|
|
D/M/YYYY | 13/9/2024 |
|
|
DD.MM.YYYY | 13.09.2024 |
|
|
DD-MM-YYYY | 13-09-2024 |
|
|
Outcome: Once a PDF document has been generated from a DOCX, fillable field tags in your DOCX document will be automatically converted into fillable fields. Such fillable fields can then be mapped as usual while configuring your bots.
