Skip to main content

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.

note

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.

Merge Field Markers

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.

Unique Invoice Numbers

Rules of Merge Fields​

There are a few simple rules you should follow when using merge fields in templates.

  1. A merge field must be enclosed in double curly braces always.
  2. A merge field can be inserted multiple times in the same template.
  3. 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.
  4. If you are merging data from Google Sheets, the column headers on your spreadsheet must exactly match the merge field names in your template.
  5. 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.
  6. Use the special Embed syntax to embed images, QR Codes, and dynamic charts in your document and emails.
  7. Use Scriptlets to manipulate dynamic content into your emails and support apps.

Special Markers​