Loops - Tables, Lists, and Repeat Sections




Loops play a very important role in document generation. We use them to populate multiple line items in invoices, list conditions in contracts, etc. The following tutorial describes how to go about loops creation.


{#tagName}{/tagName} is the syntax for loops.


Tables

EDocGen loops over the JSON/XML/Excel data files to populate table rows.


Regular Table

Role

Company

Address

{#Job} {Role}

{Company}

{Address} {/Job}


Below is the sample JSON file. The system populates the Job array into the Job table.


[ {

        "Enter_Name": "Steve",

          "Enter_Email": "Steve@mail.com",

       "Job": {

            "Role": "Engineer",

            "Company": "Cisco",

            "Address": "SanJose"

        },      

       "Job": {

            "Role": "Engineer",

            "Company": "Oracle",

            "Address": "SanJose"

        }

  }

]


Nested Table

EDocGen also supports nested tables - table inside a table.


H1

H2

H3

H4

{#table1}{#table2}{#table3}{#table4}{t41}

{t42}

{t43}

{t44}{/}{/}{/}{/}


The corresponding JSON for this table population is

[{
	"table1": [{
		"table2": [{
			"table3": [{
				"table4": [{
					"t41": "t41data",
					"t42": "t42data",
					"t43": "t43data",
					"t44": "t44data"
				}]
			}]
		}]
	}]
}]

Colored Table

You can create HTML tables in your documents by populating HTML snippet (Tag for HTML population is {>>cellstyle1}) from your data file. The tables in generated documents would have HTML styling and colors.


H1H2H3H4H5
R1C1R1C1R1C3R1C4R1C5

You can also color certain cells based on conditions. Ex: If Value>, show the cell color in red.


Filters

You can filter the rows of data that are going to be populated into your template. From the above JSON, let's say you want to populate only the row where the company name is "Oracle". Add the condition in your table as below to achieve that.


{#Job}{#Company =="Oracle"} {Role}

{Company}

{Address} {/}{/Job}

Similarly, you can have boolean conditions, to avoid creating empty rows.



Lists

Similarly, you can use the loops to create lists, bullets, and pages, etc.  Please see the template below.

Bullets


With EDocGen, you can easily create lists and it's very similar to loops. Let's assume you have a JSON in the following format.



[{
    "Sample": [value1, value 2,value 3]
 }]
                   	
 

And you want to create a list that looks like this.

  • value1
  • value2
  • value3

You just need to include the following loop in your template to create this list.

{#Sample}

  •   {.}

{/Sample}

EDocGen loop over the array to extract each of the values and present them in a bullet format. Similarly, you can create lists from Excel and XML data.


You can use the relevant tags for creating numbered lists in the same way.


Nested Bullets/Lists

Below is the syntax of tags for nested lists creation.

{#states}

  • state:{state}
  • cities
  •             {#cities}

                    -{.}

                {/cities}

{/states}


The corresponding JSON for it is

[{

     "states": [{
                "state": "state1",
                "cities": ["City1", "City2", "City3"]
                 }, 
                {
                "state": "state2",
                 "cities": ["1", "2", "3"]
                }]
}] 	
 

Repeat Sections



You can use the englishsample.json file to create multiple pages of the above template. It produces a section for each noun.


Though this example is creating repeating sections, it's also creating multiple lists inside it. This is another case of the nested list.

        {#ExampleSentences}

  • {.}

        {/ExampleSentences}