Embedding merge fields into a DOCX template

A merge field is a placeholder that you put in your DOCX template, which Inkit will later replace with actual data that you provide in your merge parameters when generating a document.

Property fields

The simplest merge field that you can embed into a DOCX template is a property field without any object structure or instance reference. For example, take the following merge parameters:

"merge_parameters": {"first_name": "John", "last_name": "Doe"}

It contains two property fields, first_name and last_name. To embed either into your DOCX template, you would insert them into the body of your document between double-curly brackets ({{}}) like this:

{{last_name}}

Object fields

An object field is like a property field, but it exists within a named object, so you must reference it using dot notation. In these merge parameters, we have the same fields as in the previous example, but they are stored within an object called name:

"merge_parameters": {"name": {"first": "John", "last": "Doe"}}

To embed the last name into your DOCX template from this data object, you would insert the following field into the body of your document:

{{name.last}}

List fields

A list field is like an object field, but it represents data in an array, so you must reference the instance using bracket notation. In these merge parameters, we have the same fields as in the previous example but within an array:

"merge_parameters": {"names": [{"first": "John", "last": "Doe"}, {"first": "Jane", "last": "Smith"}]}

While you would normally embed list fields as ordered/unordered lists and tables, you can also embed individual elements from the array. To embed John Doe's last name into your DOCX template from this data object, you would insert the following field into the body of your document:

{{names[0].last}}

Image fields

An image field is a special type of merge field that lets you insert a named image into your Inkit template. Its merge parameters have the following format:

{#IMAGE::public_url::W=width_in_px,H=height_in_px,WRAP=wrap_type#}

public_url is the image URL, W is the width of the image in pixels, H is the height of the image in pixels and WRAP is the image wrapping type.

In these merge parameters, we will define an image referenced by a property called IMAGE1:

"merge_parameters": {
        "IMAGE1": "{#IMAGE::https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png::W=100,H=100,WRAP=INLINE#}",
}

To embed this image into your DOCX template, you would insert the following field into the body of your document:

{{IMAGE1}}

📘

Note: While you can embed images into your Inkit template, you cannot embed videos.

To see these merge fields in action, check out how to build a full-featured DOCX template.