How to Use Merge Fields or {{Markers}} in Templates
Document Studio lets you create personalized documents and emails from templates. These templates include merge fields, enclosed in double curly braces, to personalize your documents and email messages with information from the data source which could either be a Google Sheet or a Google Forms response.
If you have previously from a different document generation solution, that app could have used a different name to identify merge fields. They could be called Template Tags, Placeholders, Markers, or maybe just Variables.
Merge Fields Exampleβ
Merge Fields indicate where should the app populate dynamic information in your document and where that information should come from. Document Studio will replace all merge fields in your template with actual input data from Google Sheets (or Google Forms) to generate the output document.
For instance, if a question in your Google Form says What is your name
, the marker that will be used in the email or document template will be {{What is your name}}
.
Let's start with a simple template.
{{ Common Name }}
belongs to the family of{{ Family Name }}
plants and itβs scientific name is{{ Scientific Name }}
The above template contains three merge fields, Common Name
, Family name
and Scientific Name
, and they can be easily recognized since the fields are surrounded with double curly braces.
Formula Markersβ
You can create additional columns in the source Google Spreadsheet with formulas and use the column titles as markers in your template.
The spreadsheet contains a column called Invoice Number
that contains the unique invoice number for each row generated by an Array Formula using the invoice date and the position of the row in the spreadsheet.
=ArrayFormula(
IF(ROW(A:A)=1,"Invoice Number",
IF(ISBLANK(A:A),"", "DI/"&RIGHT(REPT(0,5)&ROW(A:A),5)&"/"&YEAR(B:B))))
The above formula will generate a unique invoice number for each row in the spreadsheet as long as there are no blank rows. If there are blank rows, the formula will generate a blank cell.
You can now use the marker {{ Invoice Number }}
in your template though it was not available in the source spreadsheet.
Rules of Merge Fieldsβ
There are a few simple rules you should follow when using merge fields in templates.
- A merge field must be enclosed in double curly braces always.
- A merge field can be inserted multiple times in the same template.
- Each merge field in the document template should map to a column in the data source else that field will be replaced with an empty string.
- If you are merging data from Google Sheets, the column headers on your spreadsheet must exactly match the merge field names in your template.
- If you are merging data from Google Forms, the question titles on your form must exactly match the merge field names in the document template.
- Use the special Embed syntax to embed images, QR Codes, and dynamic charts in your document and emails.
- Use Scriptlets to manipulate dynamic content into your emails and support apps.