With the help of Box Doc Gen template tags, you can easily create and author document templates used to dynamically generate custom documents instantly. When a document generation process takes place, the pre-configured Box Doc Gen template automatically identifies the Box Doc Gen tags within the template, matches the tags with the fields in the JSON input data, and replaces the tags with the appropriate data to dynamically generate a document.
Template tags can be used to dynamically generate text, images, tables, lists, blocks of content, or even Box Sign tags.
Text tags
A text tag is any data field of type, string, number, or date. For example, the following fields can become text tags:
- id
- date
- customerId
- customerName
- currency
- amount
{ "invoice":{ "id": "Inv1203", "date": "13-03-2023", "customerId": "90158", "customerName": "Acme Inc", "currency": "$", "amount": 5060.50 } }
In the output document generated, all the template tags will be replaced with the input data.
Document template | Output document |
Invoice Invoice id: {{invoice.id}} Invoice date: {{invoice.date}}
{{invoice.currency}}{{invoice.amount}} |
Invoice Invoice id: Inv1203 Invoice date: 13-03-2023
$5060.50 |
Formatting text tags
Input format | Input data | Output data |
Supported via script |
Supported via Add-in |
{{invoice.customerName :: uppercase}} | Acme Inc | ACME INC | Yes | No |
{{invoice.customerName :: lowercase}} | Acme Inc | acme inc | Yes | No |
{{invoice.date :: format( “dd-mm-yyyy”) }} |
13-03-2023 | 13-03-2023 | Yes | No |
{{invoice.date :: format(“mm-dd-yyyy”) }} | 13-03-2023 | 03-13-2023 | Yes | No |
{{invoice.date :: format(“dd-mmm-yy”) }} | 13-03-2023 | 13-Mar-22 | Yes | No |
{{invoice.id :: format(“xxx-xxxx”) }} | Inv1203 | Inv-1203 | Yes | No |
Image tags
An image tag can be used to dynamically add and render images. Box Doc Gen supports images in base64 format.
To add image tags to your Box Doc Gen template:
- Insert a placeholder image, position it, and resize it to your needs
- Add a $image-path variable to the image under Alt text. Under the image path, refer to the variable in the JSON data that holds your image in base64.
For the sample JSON code below, we refer to contract.logo to have the base64:
{
"image-path": "contract.logo”,
"alt-text": "Alt text"
}
During the document generation process, Box Doc Gen replaces the placeholder image with the base64 value associated with the key identified.
{ "contract":{ "customerId": "1203", "date": "18-08-2023", "country": "UK", "customerName": "Example Corporation", "logo": "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hhtHtx20VHsuHAf7eRSrKI2Ze+z0omEbO22qzWDTRLzaE4PAuouXxg5WP/sSH18yuWfnc69ArqgdMVjAP2g6rAczjMPtneW+C4d7HrDpWCKRjguG5R5YlcOwbK6iA6V4o+wXG3S476G+Ux0bhD2qY5dlRhdpJ0OSVdWfDTi8ST9GFM6QwyIsTOpEqLfh1J1l77P6y+yokDn8C55u/zwJyideA1yjFwRj8s96jLiarZaXUUKHNadZ64Q2KaIPIOvwhYrce2e78YXutvCPCOudJ5zDuEL+o9GDjHTjpfoubS4S9Kwd97cgpYftJ4eTrQi9/oEfsbIfXxXfV3pmPqI1K2Xav/XMvFJV7ZMcoeWElY4q5jNFUFpjzof43b9873JZbKG/vYFPmdaHwbVjtp4N7zerjhtrEbLhP+n14GCHk3blGcr/HzoGleO/x/wAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjQtMDctMjBUMDM6MTg6MDUrMDA6MDDzlDIjAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDI0LTA3LTIwVDAzOjE4OjA1KzAwOjAwgsmKnwAAAABJRU5ErkJggg==", "customerAddress":{ "street": "Example street", "city": "Example city", "zip": "EX-456" } } }
Document Template
Output
Box Doc Gen replaces the placeholder image with the base64 value associated with the key identified.
The output on the generated document will display as follows:
Table tags
An array from the input data can be used to generate and dynamically format a table.
In the following example:
- items is an array that can be rendered as a dynamic table.
- id, name, quantity, price, amount are the variables within the array that can be rendered as individual columns to the dynamic table.
{ "invoice":{ "number": "Inv1203", "date": "13-03-2023", "customerId": "90158", "currency": "$", "amount": 5060.50, "items": [ { "id": 1, "name": "A4 Papers", "quantity": 100, "price": 29, "amount": 2900 }, { "id": 2, "name": "Ink Cartridge", "quantity": 40, "price": 39, "amount": 1560 }, { "id": 3, "name": "Adhesive tape", "quantity": 20, "price": 30, "amount": 600.50 } ] } }
Document Template
The document template with inserted tags will look as follows:
Id | Name | Qty | Price |
{{tablerow item in invoice.items}} | |||
{{item.id}} | {{item.name}} | {{item.quantity}} | {{item.price}} |
{{endtablerow}} |
Output
Box Doc Gen automatically identifies the table tags added to the document template, matches them with the fields in the input JSON data, and performs a few iterations to generate a complete table for the input data.
The output table on the generated document will look as follows:
Id | Name | Qty | Price |
1 | A4 Papers | 100 | 29 |
2 | Ink Cartridge | 40 | 39 |
3 | Adhesive tape | 20 | 30 |
List tags
An array from the input data can be used to dynamically generate an ordered or unordered list.
In the following example:
- items is an array that can be rendered as a dynamic list.
- id, name, quantity, price, amount are the variables within the array that can be rendered as a repetitive field in the list.
{ "invoice":{ "number": "Inv1203", "date": "13-03-2023", "customerId": "90158", "currency": "$", "amount": 5060.50, "items": [ { "id": 1, "name": "A4 Papers", "quantity": 100, "price": 29, "amount": 2900 }, { "id": 2, "name": "Ink cartridge", "quantity": 40, "price": 39, "amount": 1560 }, { "id": 3, "name": "Adhesive tape", "quantity": 20, "price": 30, "amount": 600.50 } ] } }
The input data can be used to generate different types of lists:
Use case | Document template | Output document |
Adding a bullet list |
List of products: {{ for item in invoice.items }}
|
List of products:
|
Adding a bullet list with one or more variables |
List of products: {{ for item in invoice.items }}
{{ endfor }} |
List of products:
|
Adding a squared bullet list with one or more variables |
List of products: {{ for item in invoice.items }}
{{ endfor }} |
List of products:
|
Adding a white bullet list with one or more variables |
List of products: {{ for item in invoice.items }}
{{ endfor }} |
List of products:
|
Adding a numbered list with one or more variables |
List of products: {{ for item in invoice.items }}
{{ endfor }} |
List of products:
|
Adding a roman numbered list with one or more variables |
List of products: {{ for item in invoice.items }}
{{ endfor }} |
List of products:
|
Adding an alphabetical list with one or more variables |
List of products: {{ for item in invoice.items }}
{{ endfor }} |
List of products:
|
Formatting lists
Box Doc Gen templates support a wide range of custom codes that you can use in the document template. Taking the following JSON input data as an example, you can introduce different separators and delimiters.
{ "items": ["A4 Papers", "Ink cartridge", "Adhesive tape"] }
Type of list | Document template | Output document |
List - with comma separator | {{ items :: delimiter(“,”)}} | A4 Papers, Ink cartridge, Adhesive tape |
List - with semicolon separator | {{ items :: delimiter(“;”)}} | A4 Papers; Ink cartridge; and Adhesive tape |
List - with customer separator | {{ items :: delimiter(“~”)}} | A4 Papers~ Ink cartridge~ Adhesive tape |
List - with Comma and last delimiter | {{ items :: delimiter(“,”) , lastdelimiter (“, and”)}} | A4 Papers, Ink cartridge, and Adhesive tape |
List - with semicolon and last delimiter | {{ items :: delimiter(“;”) , lastdelimiter (“; and”)}} | A4 Papers; Ink cartridge; and Adhesive tape |
List - with custom separator and last delimiter | {{ items | delimiter(“~”)}}, lastdelimiter (“~ and”)}} | A4 Papers~ Ink cartridge~ and Adhesive tape |
Conditions
You can use conditions to add input to the output document. The Box Doc Gen Template Creator add-in can help you define these conditions within the document template.
Supported conditions and operators
Tag type | Conditions supported | Operators supported to chain conditions |
String | ==(is equal to), !=(is not equal to), isPresent | AND, OR |
Date | isPresent | AND, OR |
Number | <, >, ==, !=, >=, <= | AND, OR |
The following JSON serves as input for defining conditions for the Box Doc Gen template.
{ "invoice":{ "number": "Inv1203", "date": "13-03-2023", "customerId": "90158", "currency": "$", "amount": 5060.50, "paymentMethod": "Cheque", "paymentTerms": "Net60", "deliveryDate": "23-03-2023", "items": [ { "id": 1, "name": "A4 Papers", "quantity": 100, "price": 29, "amount": 2900 }, { "id": 2, "name": "Ink cartridge", "quantity": 40, "price": 39, "amount": 1560 }, { "id": 3, "name": "Adhesive tape", "quantity": 20, "price": 30, "amount": 600.50 } ] } }
Use case | Document template | Output document |
Introducing content based on payment method and payment terms |
Payment terms: {{ if invoice.paymentMethod == “Online Transfer” AND invoice.paymentTerms == “Net30” }}
{{ elseif invoice.paymentMethod == “Cheque” AND invoice.paymentTerms == “Net60” }}
{{else}}
{{endif}} |
Payment terms:
|
Adding processing fees based on invoice amount, and payment method |
Processing fees: {{ if invoice.amount > 1000 AND invoice.amount < 5000 AND invoice.paymentMethod == “Cheque” }}
{{ elseif invoice.amount > 5000 AND invoice.paymentMethod == “Cheque”}}
{{else}}
{{endif}} |
Processing fees:
|
Adding delivery terms based on delivery date on invoice |
Delivery terms: {{ if invoice.deliveryDate isPresent }}
{{else}}
|
Delivery terms:
|
Calculations
Box Doc Gen templates support dynamic calculations. You can either write the computation code to the tagging language manually, or use the Box Doc Gen Template Creator add-in.
Sample code calculations include:
- Invoice: Determining the net invoice amount from individual line items.
Example: Sum (Individual Line item amounts in the invoice) - Purchase order: Capping the maximum sourcing amount.
Example: 5% * Net Order Value - Sales contracts: Defining penalty on SLA breach.
Example: 10% * Total Sales Value
Supported operations
Arithmetic operations | Aggregation operations |
% | Percent |
+ | SUM |
* |
AVERAGE |
- | COUNT |
The following JSON serves as input for adding calculations to the document template.
{ "invoice":{ "number": "Inv1203", "invoiceDate": "13-03-2023, 12:10 PM", "deliveryDate": "23-03-2023", "customerId": "90158", "currency": "$", "taxRate": 3, "taxAmount": 151.8, "shippingCharge": 15, "grossAmount": 5060, "penaltyRate": 10, "billCap": 25, "items": [ { "id": 1, "name": "A4 Papers", "quantity": 100, "price": 29, "amount": 2900 }, { "id": 2, "name": "Ink cartridge", "quantity": 40, "price": 39, "amount": 1560 }, { "id": 3, "name": "Adhesive tape", "quantity": 20, "price": 30, "amount": 600 } ] } }
Examples:
Use case | Document template | Output document |
To calculate net amount from the given Gross Amount and Tax Amount Arithmetic calculation |
Net Amount: {{ invoice.grossAmount + invoice.taxAmount}} |
Net Amount: Annotation: |
To calculate net amount from the given Gross Amount, Tax Rate and Shipping Charge Arithmetic calculation |
Net Amount: {{ invoice.grossAmount + invoice.taxAmount + invoice.shippingCharge}} |
Net Amount: Annotation: |
To calculate tax amount from the given Tax Rate and Gross Amount Arithmetic calculation |
Tax Amount: {{ invoice.taxRate % * invoice.grossAmount}} |
Tax Amount: Annotation: |
To calculate gross amount from individual line item amounts Aggregation calculation |
Gross Amount: {{ $sum(invoice.items.amount) }} |
Gross Amount: Annotation: |
To calculate number of line items Count calculation |
Count: {{ $count(invoice.items.amount) }} |
Count: 3 |
To calculate average of line items |
Average Amount: {{ $average(invoice.items.amount) }} |
Average Amount: 1686.66 |
To calculate net amount from the given Line Item Amount, and Tax Rate Arithmetic + Aggregation calculation |
Net Amount: {{ $sum(invoice.items.amount) + invoice.taxRate % * $sum(invoice.items.amount)}} |
Net Amount: Annotation: |
Box Sign template tags
Box Sign template tags can be added to the Box Doc Gen template for the output document created via Box Box Doc Gen to be sent for e-signature.
Box Doc Gen supports Box Sign template tags. The table below lists the tags available in the Box Doc Gen Template Creator add-in and the tagging script.
Field | Box Sign’s template code |
Supported via tagging script |
Supported via add-in |
Text field | [[t|0]] | Yes | Yes |
Date field | [[d|0]] | Yes | Yes |
Checkbox field | [[c|0]] | Yes | Yes |
Signature field | [[s|0]] | Yes | Yes |
Stamp field type | [[st|0]] | Yes | Yes |
Initials field type | [[i|0]] | Yes | Yes |
Name field type | [[n|0]] | Yes | Yes |
First name field type | [[fn|0]] | Yes | Yes |
Last name field type | [[ln|0]] | Yes | Yes |
Company field type | [[co|0]] | Yes | Yes |
Email field type | [[e|0]] | Yes | Yes |
Title field type | [[ti|0]] | Yes | Yes |
For an attachment field type | [[a|0]] | Yes | Yes |