Tables are an excellent way to present data in an organized, easy-to-read format. With DocuGenerate, you can dynamically generate tables in your documents using JSON data. Whether it’s a simple inventory list, a product catalog, or a complex financial report, tables can be created with ease.
The syntax for creating tables in your templates follows a similar structure to lists. The difference is that you’ll specify additional fields for each row of the table.
Here’s an example of how you can create a table with the headers Name, Quantity, and Price:
Name | Quantity | Price |
---|---|---|
[#items][name] | [quantity] | [price][/items] |
In this syntax, [#items]
and [/items]
denote the start and end of the loop for each row in the table. You can also use [/]
as a shorthand version to denote the end of the loop. The [name]
, [quantity]
, and [price]
tags within the loop will be replaced with the corresponding values from the JSON data.
Here’s an example of JSON data for the above template:
[{
"items": [{
"name": "Cars",
"quantity": "10",
"price": "$100"
}, {
"name": "Trains",
"quantity": "20",
"price": "$500"
}]
}]
Given the above JSON data, the template will generate the following table:
Name | Quantity | Price |
---|---|---|
Cars | 10 | $100 |
Trains | 20 | $500 |
This feature allows you to create dynamic tables in your documents, tailoring each document to the unique data it represents.