{"id":5428,"date":"2023-05-17T11:52:40","date_gmt":"2023-05-17T11:52:40","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=5428"},"modified":"2023-08-21T10:35:10","modified_gmt":"2023-08-21T10:35:10","slug":"get-started-with-bindings","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=5428","title":{"rendered":"Get started with bindings"},"content":{"rendered":"\n<p>This tutorial will introduce the fundamental principles that need to be understood when creating templates in DocuMotor using a very simple example of a contact list in Word. This is a great place to get started with creating content. Note that here we focus on injecting your data into documents rather than transforming your data. <\/p>\n\n\n\n<p>On completion of this tutorial you should have a basic understanding of:<\/p>\n\n\n\n<ol><li>Adding document and data to DocuMotor<\/li><li>The relationship between data and document content<\/li><li>How to create simple field bindings<\/li><li>How to create a simple image binding<\/li><li>How to repeat data in a document<\/li><\/ol>\n\n\n\n<h2>Before we begin<\/h2>\n\n\n\n<p>Firstly, please verify you have all the components you need to get started. These are described in the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/info.documotor.com\/?page_id=1410\" target=\"_blank\">DocuMotor Project Initiation<\/a>. You will of course need to create a new template in your tenancy to work with.<\/p>\n\n\n\n<p>This tutorial will refer to the DocuMotor Template Editor throughout. Our guide on the editor can be found <a href=\"https:\/\/info.documotor.com\/?page_id=3877\">here<\/a> and explains how to use it in detail. It is not necessary at this stage to read this guide thoroughly but you may want to refer to it at different points throughout.<\/p>\n\n\n\n<h2>The document<\/h2>\n\n\n\n<p>The document used throughout this tutorial (ContactList.docx) can be downloaded below, however the same principles can be applied to any document so if you would prefer to use a document of your own design please do so!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"537\" height=\"760\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-6.png\" alt=\"\" class=\"wp-image-5431\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-6.png 537w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-6-212x300.png 212w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-b27adc58-cde1-4b74-8dea-586c09086340\" href=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/ContactList-Template.docx\">ContactList.docx<\/a><a href=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/ContactList-Template.docx\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-b27adc58-cde1-4b74-8dea-586c09086340\">Download<\/a><\/div>\n\n\n\n<p>To add the document to the template:<\/p>\n\n\n\n<ol><li>Select the upload button from the <a href=\"https:\/\/info.documotor.com\/?page_id=4391\" data-type=\"URL\" data-id=\"https:\/\/info.documotor.com\/?page_id=4391\">edit pane<\/a>.<br><img loading=\"lazy\" width=\"176\" height=\"51\" class=\"wp-image-5435\" style=\"width: 150px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-8.png\" alt=\"\"><\/li><li>Select the template required.<\/li><\/ol>\n\n\n\n<p>You will now see a simplified version of the template within the Template Editor tab where you can add edit and remove bindings, and a preview version within the Template Preview tab.<\/p>\n\n\n\n<h2>The Data<\/h2>\n\n\n\n<p>In this tutorial we will use the data as shown below. This consists of a single field for the report name and an array of 3 contacts, each with it&#8217;s own data including an image URL. We will populate all data included here, repeating the content in the template for each element in the array.<\/p>\n\n\n\n<p>To add the data to the template:<\/p>\n\n\n\n<ol><li>Select the <a href=\"https:\/\/info.documotor.com\/?page_id=4113\" data-type=\"URL\" data-id=\"https:\/\/info.documotor.com\/?page_id=4113\">Data Pane<\/a> from the Template Editor.<\/li><li>Select the <strong>TREE<\/strong> switch which should change the pane view to <strong>EDIT<\/strong>.  <\/li><li>Replace all content within the pane with the data below. <\/li><li>Select the <strong>EDIT <\/strong>switch which should change the pane view to <strong>TREE<\/strong> and select save (CTRL + S or <img loading=\"lazy\" width=\"19\" height=\"18\" class=\"wp-image-5529\" style=\"width: 19px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-4.png\" alt=\"\">).<\/li><\/ol>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n  \"reportName\": \"Contact List\",\n  \"contacts\": [\n    {\n      \"name\": \"Jane Johnson\",\n      \"jobTitle\": \"Technical Lead\",\n      \"phone\": \"+45 70 60 50 40\",\n      \"email\": \"jane@omnidocs.com\",\n      \"image\": \"https:\/\/omnidocs.blob.core.windows.net\/dmhosting\/DALL\u00b7E 2022-10-06 11.16.49 - a corporate woman.png\"\n    },\n    {\n      \"name\": \"John Davis\",\n      \"jobTitle\": \"Software Developer\",\n      \"phone\": \"+45 60 70 40 30\",\n      \"email\": \"john@omnidocs.com\",\n      \"image\": \"https:\/\/omnidocs.blob.core.windows.net\/dmhosting\/DALL\u00b7E 2022-10-06 11.17.43 - a young professional corporate man .png\"\n    },\n    {\n      \"name\": \"Jenny Newell\",\n      \"jobTitle\": \"Chief Technology Officer\",\n      \"phone\": \"+45 20 40 90 20\",\n      \"email\": \"jenny@omnidocs.com\",\n      \"image\": \"https:\/\/omnidocs.blob.core.windows.net\/dmhosting\/DALL\u00b7E 2023-05-03 09.49.25 - photo of technology manager.png\"\n    }\n  ]\n}<\/code><\/pre>\n\n\n\n<p>Next we need to transform the data:<\/p>\n\n\n\n<ol><li>Select the Transformation Editor tab in the Edit pane<\/li><li>Add an @ sign to the root pane:<br><img loading=\"lazy\" width=\"759\" height=\"59\" class=\"wp-image-5440\" style=\"width: 500px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-10.png\" alt=\"\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-10.png 759w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/04\/image-10-300x23.png 300w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/li><\/ol>\n\n\n\n<p>For this tutorial we do not want to change the data from the payload so this will pass all information from the sample payload without being transformed. You can read more about the @ (Current node operator) <a href=\"https:\/\/info.documotor.com\/?page_id=2896#section_0\">here<\/a>.<\/p>\n\n\n\n<h2>Adding a field binding<\/h2>\n\n\n\n<p>Now both the Word document and the data are in our template, it is possible to add the first binding. In this case we will add the title of the document from the <code>reportName<\/code> field in our data. Bindings in Word documents are inserted as content controls with a tag value that contains the syntax DocuMotor needs to populate it. <\/p>\n\n\n\n<ol><li>In the Edit Pane, select the Template Editor.<\/li><li>Highlight <strong>Title <\/strong>in the document.<\/li><li>Select the Add Binding button at the top of the editor ( <img loading=\"lazy\" width=\"19\" height=\"17\" class=\"wp-image-5525\" style=\"width: 19px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image.png\" alt=\"\"> ). This presents a list of all possible bindings that can be added to the selected area of the document.<\/li><li>Select Field from the drop down menu to present the <a href=\"https:\/\/info.documotor.com\/?page_id=4229\" data-type=\"URL\" data-id=\"https:\/\/info.documotor.com\/?page_id=4229\">Field Binding<\/a> dialog:<br><img loading=\"lazy\" width=\"400\" height=\"366\" class=\"wp-image-5527\" style=\"width: 300px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-2.png\" alt=\"\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-2.png 400w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-2-300x275.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/li><li>Select the option to the right side of the <strong>Binding Key<\/strong> field to select the data to bind. This presents all data in a collapsed tree view within the current context. More on this later.<br><img loading=\"lazy\" width=\"400\" height=\"254\" class=\"wp-image-5528\" style=\"width: 300px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-3.png\" alt=\"\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-3.png 400w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-3-300x191.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/li><li>Select <strong>reportName<\/strong> then <strong>Select<\/strong>. Note how the <strong>Display Name<\/strong> field automatically changes to <em>Field: reportName<\/em>. This will become the name of the content control. It is possible to amend this name before insertion.<\/li><li>Select OK.<\/li><\/ol>\n\n\n\n<p>Now that the binding has been added, save the template in the UI and run the document (F4 or <img loading=\"lazy\" width=\"16\" height=\"16\" class=\"wp-image-5530\" style=\"width: 16px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-5.png\" alt=\"\">). The <strong>Quick Preview<\/strong> tab within the result pane will show an approximation of how the outputted document will look whilst the <strong>Fulll Preview<\/strong> will give a more accurate representation. <\/p>\n\n\n\n<h2>Adding a repeat binding<\/h2>\n\n\n\n<p><a href=\"https:\/\/info.documotor.com\/?page_id=640\">Repeat bindings<\/a> allow content within a document to be repeated as many times as necessary. Each repeated section can then be modified to contain unique data. DocuMotor will repeat defined content for each element within <a href=\"https:\/\/info.documotor.com\/?page_id=2363\">an array<\/a>. In this tutorial the sample data contains an array called <code>contacts<\/code> containing 3 objects each with the details of a single contact. We will use this to repeat the content within the document and populate each repetition with different data.  <\/p>\n\n\n\n<ol><li>In the Edit Pane, select the Template Editor and select all the content you wish to repeat. In this example that is all the content in the main body of the document except the Title.<\/li><li>Select the <strong>Add Binding<\/strong> button at the top of the editor <img loading=\"lazy\" width=\"19\" height=\"17\" class=\"wp-image-5525\" style=\"width: 19px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image.png\" alt=\"\"> and select the <strong>Repeat<\/strong> option to open the Repeat Binding dialog. Note that this dialog has an additional field compared to the field binding dialog. Each binding type has it&#8217;s own requirements and therefore the dialogs will show different options.<\/li><li>As with the field binding, select the correct binding key, in this case selecting the <strong><code>contacts<\/code><\/strong> array and select <strong>OK<\/strong>.<\/li><\/ol>\n\n\n\n<p>Running the template should now look like the image below. The content has been repeated 3 times, once for each object in the array.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"728\" height=\"622\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-7.png\" alt=\"\" class=\"wp-image-5534\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-7.png 728w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-7-300x256.png 300w\" sizes=\"(max-width: 728px) 100vw, 728px\" \/><\/figure>\n\n\n\n<h2>Adding bindings within the repeat<\/h2>\n\n\n\n<p>Now that the template content has been repeated as expected, it&#8217;s time to populate these sections with meaningful content. Our sections in this example contain two different types of content, text and pictures.<\/p>\n\n\n\n<h3>Field bindings<\/h3>\n\n\n\n<p>To populate the text, simply follow the same steps as <a href=\"https:\/\/info.documotor.com\/?page_id=5428&amp;preview=true#section_3\">above<\/a> for each relevant item. Note though that the data available to bind to is different in this case as can be seen below. As the field binding exists within a repeat binding, DocuMotor recognises the context of the data and so only the data within the <strong><code>contacts<\/code><\/strong> array is available. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"726\" height=\"316\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-9.png\" alt=\"\" class=\"wp-image-5537\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-9.png 726w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-9-300x131.png 300w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure>\n\n\n\n<p>After adding all text bindings, the result should look like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"726\" height=\"621\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-10.png\" alt=\"\" class=\"wp-image-5538\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-10.png 726w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-10-300x257.png 300w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure>\n\n\n\n<h3>Image bindings<\/h3>\n\n\n\n<p>To bind an image in DocuMotor the document needs to contain an image place. When bound the placeholder will be encapsulated within a content control. A number of different image binding types can be used depending on the circumstances and what needs to be achieved. More information these can be found <a href=\"https:\/\/info.documotor.com\/?page_id=4647\">here<\/a>. In this example we will use the FillImage type.<\/p>\n\n\n\n<ol><li>In the Edit Pane, select the Template Editor and select the image in the template.<\/li><li>Select the <strong>Add Binding<\/strong> button at the top of the editor <img loading=\"lazy\" width=\"19\" height=\"17\" class=\"wp-image-5525\" style=\"width: 19px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image.png\" alt=\"\"> and select the <strong>Fill Image <\/strong>option to open the <strong>Fill Image Binding<\/strong> dialog. <\/li><li>Select the <code>image<\/code> binding key and select OK.<\/li><\/ol>\n\n\n\n<p>After adding this and running the template, the template is complete.<\/p>\n\n\n\n<h2>Result<\/h2>\n\n\n\n<p>The final output should now look like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"557\" height=\"788\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-11.png\" alt=\"\" class=\"wp-image-5539\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-11.png 557w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/05\/image-11-212x300.png 212w\" sizes=\"(max-width: 557px) 100vw, 557px\" \/><\/figure>\n\n\n\n<p>To understand the impact on the template itself, download it using the <strong>Download Template<\/strong> (<img loading=\"lazy\" width=\"13\" height=\"11\" class=\"wp-image-5630\" style=\"width: 13px;\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/08\/image-6.png\" alt=\"\">) and open it within Word. This will now contain a content control around the <strong>Title <\/strong>text with a title of <strong>Field:reportName<\/strong> and a tag of <strong>{&#8220;BindingKey&#8221;:&#8221;reportName&#8221;,&#8221;BindingType&#8221;:&#8221;Field&#8221;}<\/strong>, the syntax required by DocuMotor.<\/p>\n\n\n\n<p>It will also contain a content control around all the content, including image, with the title of <strong>Repeat:contacts <\/strong>and the tag of <strong>{&#8220;BindingKey&#8221;:&#8221;contacts&#8221;, &#8220;BindingType&#8221;:&#8221;Repeat&#8221;}<\/strong>.<\/p>\n\n\n\n<p>Finally, inside the repeat content control there are multiple content controls containing titles and tags, similar to above mentioned, with the chosen binding types and binding keys. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will introduce the fundamental principles that need to be understood when creating templates in DocuMotor using a very simple example of a contact list in Word. This is a great place to get started with creating content. Note that here we focus on injecting your data into documents rather than transforming your data. [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"parent":2549,"menu_order":-1,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/5428"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5428"}],"version-history":[{"count":34,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/5428\/revisions"}],"predecessor-version":[{"id":5631,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/5428\/revisions\/5631"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/2549"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}