Repeating Sections or Paragraphs

Similarly to the article covering Numbered and Bulleted Lists; the Encodian population engine supports repeating sections/paragraphs, in fact, anything within a word document that could be repeated. The source JSON data must be in the form of an array, i.e. one or more items in the list.

Populate a repeating sections / paragraphs

Example Document: Encodian - Template Syntax - Repeats.docx

Example JSON Data:

{
"companyName": "Encodian",
"members": [
{
"listFirstName": "Efren",
"listLastName": "Gaskill",
"age": 45,
"homeTown": "Clearwater"
},
{
"listFirstName": "Sanly",
"listLastName": "Keyme",
"age": 19,
"homeTown": "Kensington"
},
{
"listFirstName": "Mark",
"listLastName": "Nigma",
"age": 36,
"homeTown": "Silver Spring"
}
]
}

Configure the document as required interlacing tokens within your actual content, for example:

<<foreach [member in members]>><<[member.listFirstName]>> <<[member.listLastName]>> is <<[member.age]>> years old and lives in <<[member.homeTown]>>.
<</foreach>>

mceclip2.png

This generates the following output:

mceclip0.png

Enabling null members

By default the 'Populate Word Document' actions 'Population Options' property is set to 'Default' which will throw an error if a member has a null value, i.e. the following JSON will generate the following error:

{
   "companyName": "Encodian",
   "members": []
}

mceclip0.png

The complete error message: A general error occurred populating the word document provided:  An error has been encountered at the end of expression 'member.listFirstName]>'. Can not get the value of member 'listFirstName' on type 'System.Data.DataRow'.

If elements of your JSON data could be null, then simply change the 'Population Options' property to 'AllowMissingMembers'

mceclip1.png 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk