Understanding Document Templates
Learn how Document Templates are used to create the final documents produced by MergeOS.
Document Templates are standard Word documents that you use to design your template. When MergeOS processes a row of data, it uses this template to generate one document. You can use all the MS Word features to style and layout your Document Template, and use simple placeholder variables to tell MergeOS where to insert the data. You can read more about data and how to set it up in the Understanding Datatables article.
Fundamentals
Many businesses use MS Word to create client letters, invoices and reports. A common practice is to create a master template document that contains the text, and then use placeholder text to show what needs to be replaced (e.g. <insert name here>). Someone then goes through and manually replaces the placeholder text before sending it out to the recipient. More advanced users might use the standard Word mail merge feature. MergeOS takes this same concept but adds some more powerful features. This page will show how you create Document Templates.
Placeholder Variables & Functions
There are a few places that MergeOS can source the data that we use to merge into a Document Template. All of these sources are configured within a Project. They are:
- Columns from the projects Data Table
- Output Named Ranges, Tables and Charts from a Pre-process template
- Files from your Miscellaneous files folder
- MergeOS System variables
- Your Organisation variables
- Project variables
You place variables into your Document Templates within double curly braces {{ }} to differentiate them from the standard text. Some variables require the use of a function when being inserted. The function allow you to pass through more information, such as a date format or the size of an image.
Data Table Variables
Use Data Table variables to insert values from a Data Table into your documents. Columns from the data table can be inserted by using the column name.
{{ ["Client ID"] }} {{ ["First Name"] }} {{ ["Last Name"] }}
The variables above would insert the following when the first row is merged into the document
1 Missy Coucher
Pre-process Variables
Pre-process variables come from an Excel spreadsheet configured in the pre-process step of a project.
Output Named Ranges
Use Output Named Ranges to insert values from a pre-process spreadsheet into your documents.
{{ ["pre"."variable_name"] }}
Variables from pre-process templates must start with "pre".
{{ ["pre"."full_name"] }}
The variable above would insert the following:
Missy Coucher
Chart & Graph variables
Use the Chart function and the name of a chart in the Excel pre-process template to insert charts into your documents.
{{ chart(["pre"."chart_name"]) }} {{ chart(["pre"."chart_name"], width="500", height="500") }}
Parameters
- width: The maximum width of the chart. Optional, though required if height is set.
- height: The maximum height of the chart. Optional, though required if width is set.
- preserve-ratio: True or False. If true, the chart will keep the same width to height ratio when resized. If false, the width and height will be set to the exact values. This may warp the chart.
Example
Excel Table Variables
Use the Table function with the name of an Excel Table to insert a formatted Word table into your document.
{{ table(["pre"."table_name"]) }} {{ table( ["pre"."table_name"], style="ReportJazz", header-row="true", first-column="true", total-row="false", last-column="false", banded-rows="true", banded-columns="false", align-decimals="right") }}
Parameters
All parameters are optional.
- style: Sets the style of the table using one of the table styles in the Word Document Template. You can create your own styles, name it and use that name here too. If not set, the default Word Table Grid is used.
- header-row: True or False. Set to true to display special formatting for the first row of the table.
- first-column: True or False. Set to true to display special formatting for the first column of the table.
- total-row: True or False. Set to true to display special formatting for the last row of the table.
- last-column: True or False. Set to true to display special formatting for the last column of the table.
- banded-rows: True or False. Set to true to display banded rows, in which each even rows are formatted differently from odd rows.
- banded-columns: True or False. Set to true to display banded rows, in which each even columns are formatted differently from odd columns.
- align-decimals: True or False. Set to true to right-align numbers in their column.
File Variables
Use the Image function to insert images that you have previously uploaded to your MergeOS account.
{{ image["image_reference_name"] }} {{ image(["image_reference_name"], width="100", height="100", preserve-ratio="false") }}
Parameters
- width: Number. The maximum width of the image in mm. Optional.
- height: Number. The maximum height of the image mm. Optional.
- preserve-ratio: True or False. If true, the image will keep the same width to height ratio when resized. If false, the width and height will be set to the exact values. This may warp the image.
Note: The height and width of an image is defined using millimetres. You can check the size of images in Word by going to the Picture Format tab. Multiply inches by 25.4 to convert to millimetres.
Uploading Images and setting the Image Reference Names
You can upload images to use in your templates to the Miscellaneous Files folder in your account.
Uploading Images and setting the Image Reference Names
You can upload images to use in your templates to the Miscellaneous Files folder in your account.
- Click on the Folders menu item in the left menu
- Click on the Miscellaneous Files folder
- Click on Upload File and choose an image from your computer
- Click on the Image to enter the image details page
- Click into the Reference Name text box and enter a new name
- Click on the Save button
You can now use that Image in your documents with the image function as described above.