Box Doc Gen template tags currently support English only. Test your templates to verify they meet your language requirements before production use.
1. Text tags
A text tag is any data field of type, string, number, or date. In the example below, you can turnid, date, customerId, customerName, currency, amount into text tags.
Box Doc Gen tags do not support spaces or hyphens between key words in the tag. For example,
**{{first name}}** or **{{first-name}}** are not supported.Optional tags
Default values
Formatting text tags
Rich text
Box Doc Gen allows you to generate documents with rich text. If the input JSON data contains HTML tags such as bold, italic, underline, line breaks, paragraphs, anchors, or images, Doc Gen automatically interprets them as rich text and applies the relevant formatting.| HTML Tags | JSON data | Output |
|---|---|---|
| Bold | { “company”: “<b>Acme Inc.</b> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<b> 999-999-9999</b>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Italic | { “company”: “<i>Acme Inc.</i> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<i> 999-999-9999</i>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Underline | { “company”: “<u>Acme Inc.</u> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<u> 999-999-9999</u>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Bold, Italic and Underline | { “company”: “<b><i><u>Acme Inc.</u></i></b>A fictional company that features prominently in the Road Runner show as a running gag. Phone:<b><i><u> 999-999-9999</u></i></b>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Strong | { “company”: “<strong>Acme Inc.</strong> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<strong> 999-999-9999</strong>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Span | { “company”: “<span>Acme Inc.</span> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<span> 999-999-9999</span>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Emphasized | { “company”: “<em>Acme Inc.</em> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<em> 999-999-9999</em>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Line breaks | { “company”: “<b>Acme Inc.</b> \n A fictional company that features prominently in the Road Runner show as a running gag. \n Phone:<b> 999-999-9999</b>” } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Paragraphs | { “company”: “<b>Acme Inc.</b> <p> A fictional company that features prominently in the Road Runner show as a running gag. </p> <p> Phone:<b> 999-999-9999</b>”</p> } | Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999 |
| Ordered list | <ol><li>Blue</li><li>Green</li><li>Red</li></ol> |
|
| Unordered list | <ul><li>Blue</li><li>Green</li><li>Red</li></ul> |
|
2. Image tags
Doc Gen enables you to embed any image file in Box into the generated document. To do this, you will need to follow the following steps:1. Upload the image file to Box
The image file being used for Document Generation has to be uploaded to Box. Generating documents via API If you are using a service account to generate the document via APIs, ensure the service account has access to the file.2. Author the Doc Gen template
Doc Gen allows you to generate documents using images in the following ways- Generating documents from a placeholder image
- Generating documents with HTML images
Generating documents from a placeholder image:
Authoring a Doc Gen template using Add-in for Microsoft Word To insert an Image tag using the add-in:- In the Box Doc Gen Template Creator add-in, create an image tag using your desired placeholder image
- Navigate to the Document Tags > Image Tags.
- In the document, select the area to insert an Image tag.
- Double-click the image tag to insert it.
- The image-path - is the key field for the Image from the JSON Payload used to make a request to Generate a document.
- You can also add a placeholder image by simply dragging and dropping it into the document or inserting an image placeholder. However, make sure to manually include the required code in the ALT TEXT field.
{{ tablerow item in multipleImages }} | |
{{ item.name }} | Embedded image whose Alt Text includes JSON with image-path |
{{ endtablerow }} |
Ensure to include the image path in the ALT TEXT section of the image
Generating documents with HTML images:
To generate a document with a HTML image from the JSON payload, include a Text tag in the template.This method only supports generation of simple images, and does not support generation of repeating images in For-loops and Table-loops.
3. Create the JSON Payload to Generate the document
Generating documents from a placeholder image:
To generate a document with an image file in Box, use the following schema:- Key used in the Placeholder image (Ex: singleImage)
- id - to pass the file id of the Image file in Box
- type - to signify that this is an image file to be embedded in the document
The image file id mentioned here should refer to your file id in Box.
Generating documents with HTML images:
To include an image from Box in your document using an HTML image tag, define the JSON schema in the following format:- file://2097093405102 refers to the file ID of the image stored in Box
- height and width define the display size of the image
- alt specifies the alternative text for the image
4. Make a Document Generation request
Doc Gen allows you to create documents with embedded images sourced directly from Box. You can include images in your generated documents using one of the following methods:- Box Doc Gen API – Generate documents with images programmatically. Refer to the Box Doc Gen API documentation for step-by-step guidance.
- Box Doc Gen Web App – Create documents with embedded images through the web interface. See the documentation for detailed instructions.
3. Table tags
An array from the input data can be used to generate and dynamically format a table. In the following example:itemsis an array that can be rendered as a dynamic table.id,name,quantity,price,amountare the variables within the array that can be rendered as individual columns to the dynamic table.
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:4. List tags
An array from the input data can be used to dynamically generate an ordered or unordered list. In the following example:itemsis an array that can be rendered as a dynamic list.id,name,quantity,price,amountare the variables within the array that can be rendered as a repetitive field in the list.
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.5. 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 |
Conditions with tables
Doc Gen allows you to conditionally render any content including tables, images, and so on.{{ if invoice.customerId isPresent }}
| Id | Name | Qty | Price |
|---|---|---|---|
{{tablerow item in invoice.items}} | |||
{{item.id}} | {{item.name}} | {{item.quantity}} | {{item.price}} |
{{endtablerow}} | |||
{{ endif }}
Conditions inside tables
Doc Gen allows you to conditionally render content with a column in a table. Examples| Id | Name | Qty | Price |
|---|---|---|---|
{{ tablerow item in invoice.items }} | |||
{{ item.id}} | {{ item.name}} | {{ item.quantity}} | {{ if item.price isPresent}}{{item.price}}{{ else }}-{{ endif }} |
{{ endtablerow }} | |||
6. 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
The following JSON serves as input for adding calculations to the document template.