Cognito Forms logo

Merge syntax

You can use Cognito calculation syntax when composing merge documents. When you first download your template and open it in Word, the document will appear with tables containing field names and field tokens in curly brackets (see example.)

The field names and calculations look and function the same as they do in Cognito Forms, with a few exceptions:

1. { each }

2. { if }

3. { image }

4. Page numbers

{ each }

The each tag is used when referencing repeating sections and regular sections. For example, if your repeating section is named My Order, and you have a field in the section called Product, you can reference the Product field like so:

{ each MyOrder }
Product: { Product }
{ end each }

Wherever you use the each tag, be sure to close it with { end each }. 

The each syntax also allows you to do things like sort multiple items in a repeating section. For example, using the OrderBy function, you can sort a field in alphabetical order by last name:

{ each ContactInformation.OrderBy(Name.Last) }
Name: { Name }
{ end each }

If you want to filter items, you can use the Where function. So, if you had a repeating section for event attendees, you could filter the list down to people who plan on ordering a T-shirt, along with their shirt size:

{ each Attendees.Where(TShirt = "Yes") }
Name: { Name }
Shirt Size: { ShirtSize }
{ end each }

{ if }

The if tag is used when referencing conditional if/then statements. So, if you had a field that conditionally appears depending on what your customers selects, your syntax might look something like this:

{if (DidYouFindOurCustomerServiceSatisfactory = "No")}
Please explain.
{ end if }

Wherever you use the each tag, be sure to close it with { end if }. 

{ image }

The image tag is used to display images that are uploaded to your form through a File Upload field. Normally, these images will just display as a text list (i.e. Picture1.png, Picture2.gif, Picture3.jpeg). In your Word template, the default code will look like this:

{ each FileUpload }
{ end each }

To make your uploaded images appear as actual pictures, place this image syntax before or after the default each set (or just delete the each set entirely):

{ image FileUpload }

Make sure to replace "FileUpload" with the name of your File Upload field. With this syntax, you can control the width and height of your displayed images:

{ image FileUpload, width=5in, height = 3in }

As well as the max width or max height to constrain the size of your images:

{ image FileUpload, max-width=6in, max-height=5in }

The image ratio will always be maintained when images are resized. You can specify widths and heights in points (pt), pixels (px), inches (in), or centimeters (cm). If you don't specify the unit, all sizes will be in inches. The image tag does not need to be closed.

Note: If you're displaying your images in a table, your table properties should be set to allow rows to break across pages. If not, your images will be cut off when they reach the end of the page. To select this option, click inside your table and go to the Layout section in Table Tools. Next, find Select and choose Select Row:

In the Table Properties dialog, make sure that "Allow row to break across pages" is checked:


Page numbers

When working with document page numbers, press Alt+F9 to view/edit the field tokens. You can move page numbers out of the bottom footer to the top footer, or anywhere else on your form:

Printable View