> ## Documentation Index
> Fetch the complete documentation index at: https://docs.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Template Tags Reference

<div className="article_labels_list" style={{display: 'none'}} dangerouslySetInnerHTML={{__html: "End User , Established , P5 , Box Doc Gen"}} />

<Note>
  **Note**: Box Doc Gen template tags currently support English only. Test your templates to verify they meet your language requirements before production use.
</Note>

Template tags let you create document templates that automatically fill in with data. When you generate a document, Box Doc Gen finds the tags in your template, matches them to fields in your JSON input, and replaces each tag with the corresponding value.

Use template tags to dynamically generate:

1. [Text](#1-text-tags)
2. [Images](#2-image-tags)
3. [Tables](#3-table-tags)
4. [Lists](#4-list-tags)
5. [Conditions](#5-conditions)
6. [Calculations](#6-calculations)
7. [Box Sign template tags](#7-box-sign-template-tags)

<h2 id="1-text-tags">
  1\. Text tags
</h2>

A text tag is any data field of type, string, number, or date. In the example below, you can turn `id`, `date`, `customerId`, `customerName`, `currency`, `amount` into text tags.

```json theme={null}
{
  "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.

<Note>
  **Note:** 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.
</Note>

| <strong>Document template</strong>                                                                                                                                                                                                                                                                                                                                                                                                           | <strong>Output document</strong>                                                                                                                                                                                                                                                     |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <strong>Invoice</strong><br /><strong>Invoice id: </strong><code>\{\{invoice.id}}</code><br /><strong>Invoice date:</strong> <code>\{\{invoice.date}}</code><br /><strong>Customer details:</strong><br />Customer id: <code>\{\{invoice.customerId}}</code><br />Customer name: <code>\{\{invoice.customerName}}</code><br /><strong>Amount Payable:</strong><br /><code><strong>\{\{invoice.currency}}\{\{invoice.amount}}</strong></code> | <strong>Invoice</strong><br /><strong>Invoice id: </strong>Inv1203<br /><strong>Invoice date:</strong> 13-03-2023<br /><strong>Customer details:</strong><br />Customer id: 90158<br />Customer name: Acme Inc<br /><strong>Amount Payable:</strong><br /><strong>\$5060.50</strong> |

### Optional tags

| <strong>Input format</strong>                       | <strong>Input data</strong> | <strong>Output data</strong> |
| --------------------------------------------------- | --------------------------- | ---------------------------- |
| <code>\{\{invoice.customerName}}</code>             | -                           | \{\{invoice.customerName}}   |
| <code>\{\{invoice.customerName :: optional}}</code> | -                           |                              |

### Default values

| <strong>Input format</strong>                                 | <strong>Input data</strong> | <strong>Output data</strong> |
| ------------------------------------------------------------- | --------------------------- | ---------------------------- |
| <code>\{\{invoice.customerName}}</code>                       | -                           | \{\{invoice.customerName}}   |
| <code>\{\{invoice.customerName :: default(“Box Inc”)}}</code> | -                           | Box Inc                      |

### Formatting text tags

| <strong>Input format</strong>                                               | <strong>Input data</strong> | <strong>Output data</strong> | <strong>Supported </strong><br /><strong>via script</strong> | <strong>Supported </strong><br /><strong>via Add-in</strong> |
| --------------------------------------------------------------------------- | --------------------------- | ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| <code>\{\{invoice.customerName :: uppercase}}</code>                        | Acme Inc                    | ACME INC                     | Yes                                                          | No                                                           |
| <code>\{\{invoice.customerName :: lowercase}}</code>                        | Acme Inc                    | acme inc                     | Yes                                                          | No                                                           |
| <code>\{\{invoice.date :: format(</code><br /><code>“dd-mm-yyyy”) }}</code> | 13-03-2023                  | 13-03-2023                   | Yes                                                          | No                                                           |
| <code>\{\{invoice.date :: format(“mm-dd-yyyy”) }}</code>                    | 13-03-2023                  | 03-13-2023                   | Yes                                                          | No                                                           |
| <code>\{\{invoice.date :: format(“dd-mmm-yy”) }}</code>                     | 13-03-2023                  | 13-Mar-22                    | Yes                                                          | No                                                           |
| <code>\{\{invoice.id :: format(“xxx-xxxx”) }}</code>                        | Inv1203                     | Inv-1203                     | Yes                                                          | No                                                           |
| <code>\{\{invoice.amount :: format(“EU-Number”) }}</code>                   | 300000                      | 300.000                      | Yes                                                          | No                                                           |
| <code>\{\{invoice.amount :: format(“US-Number”) }}</code>                   | 300000                      | 300,000                      | Yes                                                          | No                                                           |

### 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.

<table><thead><tr><th><strong>HTML Tags</strong></th><th><strong>JSON data</strong></th><th><strong>Output</strong></th></tr></thead><tbody><tr><td><strong>Bold</strong></td><td><code>\{ "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>" }</code></td><td><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></td></tr><tr><td><strong>Italic</strong></td><td><code>\{ "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>" }</code></td><td><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></td></tr><tr><td><strong>Underline</strong></td><td><code>\{ "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>" }</code></td><td>Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999</td></tr><tr><td><strong>Bold, Italic and Underline</strong></td><td><code>\{ "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>" }</code></td><td><em><strong>Acme Inc</strong>.</em> A fictional company that features prominently in the Road Runner show as a running gag. Phone: <em><strong>999-999-9999</strong></em></td></tr><tr><td><strong>Strong</strong></td><td><code>\{ "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>" }</code></td><td><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></td></tr><tr><td><strong>Span</strong></td><td><code>\{ "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>" }</code></td><td>Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999</td></tr><tr><td><strong>Emphasized</strong></td><td><code>\{ "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>" }</code></td><td><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></td></tr><tr><td><strong>Line breaks</strong></td><td><code>\{ "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>" }</code></td><td><strong>Acme Inc. </strong> <br />A fictional company that features prominently in the Road Runner show as a running gag. <br />Phone: <strong>999-999-9999</strong></td></tr><tr><td><strong>Paragraphs</strong></td><td><code>\{ "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> }</code></td><td><strong>Acme Inc. </strong><br />A fictional company that features prominently in the Road Runner show as a running gag. <br />Phone: <strong>999-999-9999</strong></td></tr><tr><td><strong>Ordered list</strong></td><td><code>\<ol>\<li>Blue\</li>\<li>Green\</li>\<li>Red\</li>\</ol></code></td><td><ol><li>Blue</li><li>Green</li><li>Red</li></ol></td></tr><tr><td><strong>Unordered list</strong></td><td><code>\<ul>\<li>Blue\</li>\<li>Green\</li>\<li>Red\</li>\</ul></code></td><td><ul><li>Blue</li><li>Green</li><li>Red</li></ul></td></tr></tbody></table>

***

<span id="h_01JH9N4NTD93TD40270YTTBWYW" />

<h2 id="2-image-tags">
  2\. Image tags
</h2>

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:

1. In the Box Doc Gen Template Creator add-in, create an image tag using your desired placeholder image
2. Navigate to the **Document Tags** > **Image Tags**.
3. In the document, select the area to insert an Image tag.
4. Double-click the image tag to insert it.

The result is a placeholder image, which can be dynamically replaced by the input data from the Box Doc Gen API, or any other upstream systems.

Placeholder.png

The dimensions, and alignments of the placeholder image can be altered using Microsoft Word functions. These properties are retained in the output document.

The placeholder image has the following code added to the image under "Alt Text". To view it: **Select the image** -> **Right Click** -> **View Alt Text**

```json theme={null}
{
  "image-path": "singleImage",
  "alt-text": ""
}
```

Note:

* 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.

**Repeating images within a for-loop:**

To generate a document with multiple images in a for-loop, ensure the image is wrapped in a ***For function*** as below,

```
{{ for item in multipleImages }}

{
  "image-path": "{{ item.id }}",
  "alt-text": ""
}

{{ endfor }}
```

**Repeating images within a table-loop:**

To generate a document with multiple images in a table-loop, ensure the image is wrapped in a ***Table function*** as below,

<table><tbody><tr><td><code>\{\{ tablerow item in multipleImages }}</code></td><td /></tr><tr><td><code>\{\{ item.name }}</code></td><td>Embedded image whose Alt Text includes JSON with <code>image-path</code></td></tr><tr><td><code>\{\{ endtablerow }}</code></td><td /></tr></tbody></table>

Note: Ensure to include the image path in the ALT TEXT section of the image

```json theme={null}
{
  "image-path": "singleImage",
  "alt-text": ""
}
```

#### Generating documents with HTML images:

To generate a document with a HTML image from the JSON payload, include a Text tag in the template.

```
For example: {{htmlImage}}
```

**Note:** 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:

1. **Key** used in the Placeholder image (Ex: singleImage)
2. **id** - to pass the file id of the Image file in Box
3. **type** - to signify that this is an image file to be embedded in the document

```json theme={null}
{
  "singleImage": {
    "id": "1948600448426",
    "type": "image",
    "name": "Title for image 1"
  }
}
```

Note: The image file id mentioned here should refer to your file id in Box.

```json theme={null}
{
  "image-path": "singleImage",
  "alt-text": ""
}
```

**Generating a document from a Placeholder with multiple images**

To generate a document with multiple image files in Box, run an array of image schema as shown below,

```json theme={null}
{
  "multipleImages": [
    {
      "id": "1948600448426",
      "type": "image",
      "name": "Title for image 2"
    },
    {
      "id": "1948600448427",
      "type": "image",
      "name": "Title for image 3"
    },
    {
      "id": "1948600448428",
      "type": "image",
      "name": "Title for image 4"
    }
  ]
}
```

##### **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:

```json theme={null}
{
  "htmlImage": "<img src='file://2097093405102' alt='here is a sample image' height='500' width='500'/>"
}
```

In this example:

* **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.

**Salesforce Integration** – Generate documents with images by referencing a Box file ID. Ensure the required JSON schema pattern is followed. For setup and usage, refer to the Salesforce integration documentation.

***

<h2 id="3-table-tags">
  3\. Table tags
</h2>

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.

```json theme={null}
{
  "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:

<table><thead><tr><th><strong>Id</strong></th><th><strong>Name</strong></th><th><strong>Qty</strong></th><th><strong>Price</strong></th></tr></thead><tbody><tr><td colspan="4"><code>\{\{tablerow item in invoice.items}}</code></td></tr><tr><td><code>\{\{item.id}}</code></td><td><code>\{\{item.name}}</code></td><td><code>\{\{item.quantity}}</code></td><td><code>\{\{item.price}}</code></td></tr><tr><td colspan="4"><code>\{\{endtablerow}}</code></td></tr></tbody></table>

### 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:

| <strong>Id</strong> | <strong>Name</strong> | <strong>Qty</strong> | <strong>Price</strong> |
| ------------------- | --------------------- | -------------------- | ---------------------- |
| 1                   | A4 Papers             | 100                  | 29                     |
| 2                   | Ink Cartridge         | 40                   | 39                     |
| 3                   | Adhesive tape         | 20                   | 30                     |

***

<h2 id="4-list-tags">
  4\. List tags
</h2>

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.

```json theme={null}
{
  "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:

| <strong>Use case</strong>                                                | <strong>Document template</strong>                                                                                                                                                            | <strong>Output document</strong>                                                                                    |
| ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| <strong>Adding a bullet list</strong>                                    | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />• <code>\{\{item.name}}</code><br /><code>\{\{ endfor }}</code>                       | <strong>List of products:</strong><br /><br />• A4 Papers<br />• Ink cartridge<br />• Adhesive tape                 |
| <strong>Adding a bullet list with one or more variables</strong>         | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />• <code>\{\{item.name}}, \{\{item.quantity}}</code><br /><code>\{\{ endfor }}</code>  | <strong>List of products:</strong><br /><br />• A4 Papers, 100<br />• Ink cartridge, 40<br />• Adhesive tape, 20    |
| <strong>Adding a squared bullet list with one or more variables</strong> | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />• <code>\{\{item.name}}, \{\{item.quantity}}</code><br /><code>\{\{ endfor }}</code>  | <strong>List of products:</strong><br /><br />• A4 Papers, 100<br />• Ink cartridge, 40<br />• Adhesive tape, 20    |
| <strong>Adding a white bullet list with one or more variables</strong>   | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />• <code>\{\{item.name}}, \{\{item.quantity}}</code><br /><code>\{\{ endfor }}</code>  | <strong>List of products:</strong><br /><br />• A4 Papers, 100<br />• Ink cartridge, 40<br />• Adhesive tape, 20    |
| <strong>Adding a numbered list with one or more variables</strong>       | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />1. <code>\{\{item.name}}, \{\{item.quantity}}</code><br /><code>\{\{ endfor }}</code> | <strong>List of products:</strong><br /><br />1. A4 Papers, 100<br />2. Ink cartridge, 40<br />3. Adhesive tape, 20 |
| <strong>Adding a roman numbered list with one or more variables</strong> | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />1. <code>\{\{item.name}}, \{\{item.quantity}}</code><br /><code>\{\{ endfor }}</code> | <strong>List of products:</strong><br /><br />1. A4 Papers, 100<br />2. Ink cartridge, 40<br />3. Adhesive tape, 20 |
| <strong>Adding an alphabetical list with one or more variables</strong>  | <strong>List of products:</strong><br /><br /><code>\{\{ for item in invoice.items }}</code><br /><br />1. <code>\{\{item.name}}, \{\{item.quantity}}</code><br /><code>\{\{ endfor }}</code> | <strong>List of products:</strong><br /><br />1. A4 Papers, 100<br />2. Ink cartridge, 40<br />3. Adhesive tape, 20 |

### 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.

```json theme={null}
{
  "items": ["A4 Papers", "Ink  cartridge", "Adhesive tape"]
}
```

| <strong>Type of list</strong>                                    | <strong>Document template</strong>                                      | <strong>Output document</strong>              |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------- |
| <strong>List - with comma separator </strong>                    | <code>\{\{ items :: delimiter(“,”)}}</code>                             | A4 Papers, Ink cartridge, Adhesive tape       |
| <strong>List - with semicolon separator </strong>                | <code>\{\{ items :: delimiter(“;”)}}</code>                             | A4 Papers; Ink cartridge; and Adhesive tape   |
| <strong>List - with customer separator</strong>                  | <code>\{\{ items :: delimiter(“\~”)}}</code>                            | A4 Papers\~ Ink cartridge\~ Adhesive tape     |
| <strong>List - with Comma and last delimiter</strong>            | <code>\{\{ items :: delimiter(“,”) , lastdelimiter (“, and”)}}</code>   | A4 Papers, Ink cartridge, and Adhesive tape   |
| <strong>List - with semicolon and last delimiter</strong>        | <code>\{\{ items :: delimiter(“;”) , lastdelimiter (“; and”)}}</code>   | A4 Papers; Ink cartridge; and Adhesive tape   |
| <strong>List - with custom separator and last delimiter</strong> | <code>\{\{ items \| delimiter(“~~”) , lastdelimiter (“~~ and”)}}</code> | A4 Papers\~ Ink cartridge\~ and Adhesive tape |

***

<h2 id="5-conditions">
  5\. Conditions
</h2>

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

<table><thead><tr><th><strong>Tag type</strong></th><th><strong>Conditions supported</strong></th><th><strong>Operators supported to chain conditions</strong></th></tr></thead><tbody><tr><td>String</td><td>==(is equal to), !=(is not equal to), isPresent</td><td>AND, OR</td></tr><tr><td>Date</td><td>isPresent</td><td>AND, OR</td></tr><tr><td>Number</td><td>\<, >, ==, !=, >=, \<=</td><td>AND, OR</td></tr></tbody></table>

The following JSON serves as input for defining conditions for the Box Doc Gen template.

```json theme={null}
{
  "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
      }
    ]
  }
 }
```

| <strong>Use case</strong>                                                           | <strong>Document template</strong>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | <strong>Output document</strong>                                                                                                                                                                                                                                                                                  |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <strong>Introducing content based on payment method and payment terms</strong>      | <strong>Payment terms:</strong><br /><br /><code>\{\{ if invoice.paymentMethod == “Online Transfer” AND invoice.paymentTerms == “Net30” }} </code><br /><br />• The invoice must be paid within 30 calendar days of the invoice date.<br />• The payment reference should contain the invoice number as reference.<br /><code>\{\{ elseif invoice.paymentMethod == “Cheque” AND invoice.paymentTerms == “Net60” }} </code><br /><br />• The invoice must be paid within 60 calendar days of the invoice date.<br />• The payment reference should contain the invoice number as reference.<br />• <strong>CHECK MADE PAYABLE TO: </strong>Box Inc, 900 Jefferson Ave, Redwood City, CA 94063, United States.<br /><code>\{\{else}}</code><br /><br />• The invoice must be paid must pay within 7 calendar days of the invoice date.<br /><code>\{\{endif}}</code> | <strong>Payment terms:</strong><br /><br />• The invoice must be paid within 60 calendar days of the invoice date.<br />• The payment reference should contain the invoice number as reference.<br />• <strong>CHECK MADE PAYABLE TO: </strong>Box Inc, 900 Jefferson Ave, Redwood City, CA 94063, United States. |
| <strong>Adding processing fees based on invoice amount, and payment method</strong> | <strong>Processing fees:</strong><br /><br /><code>\{\{ if invoice.amount >  1000 AND invoice.amount \< 5000 AND invoice.paymentMethod == “Cheque” }} </code><br /><br />• There will be an additional 1% processing fee that will be added to your account.<br />• The processing fee will be included to your next invoice.<br /><code>\{\{ elseif invoice.amount > 5000 AND invoice.paymentMethod == “Cheque”}} </code><br /><br />• The invoice can be paid via check or online transfer without any added processing fees.<br /><code>\{\{else}}</code><br /><br />• The invoice must be paid within 7 calendar days of the invoice date.<br /><code>\{\{endif}}</code>                                                                                                                                                                                       | <strong>Processing fees:</strong><br /><br />• The invoice can be paid via check or online transfer without any added processing fees.                                                                                                                                                                            |
| <strong>Adding delivery terms based on delivery date on invoice</strong>            | <strong>Delivery terms:</strong><br /><br /><code>\{\{ if invoice.deliveryDate isPresent }} </code><br /><br />• Your order shall be delivered on <code><strong>\{\{ invoice.deliveryDate}}</strong></code>.<br />• Orders delivered can be returned within 10 days of delivery.<br /><code>\{\{else}}</code><br /><br />• Your order shall be delivered within the next 7 days.<br />• Orders delivered can be returned within 10 days from the date of delivery.                                                                                                                                                                                                                                                                                                                                                                                                 | <strong>Delivery terms:</strong><br /><br />• Your order will be delivered on <strong>23-03-2023</strong>.<br />• Orders delivered can be returned within 10 days of delivery.                                                                                                                                    |

<h3 id="conditions-with-tables">
  Conditions with tables
</h3>

Doc Gen allows you to conditionally render any content including tables, images, and so on.

`{{ if invoice.customerId isPresent }}`

<table><thead><tr><th><strong>Id</strong></th><th><strong>Name</strong></th><th><strong>Qty</strong></th><th><strong>Price</strong></th></tr></thead><tbody><tr><td colspan="4"><code>\{\{tablerow item in invoice.items}}</code></td></tr><tr><td><code>\{\{item.id}}</code></td><td><code>\{\{item.name}}</code></td><td><code>\{\{item.quantity}}</code></td><td><code>\{\{item.price}}</code></td></tr><tr><td colspan="4"><code>\{\{endtablerow}}</code></td></tr></tbody></table>

`{{ endif }}`

### Conditions inside tables

Doc Gen allows you to conditionally render content with a column in a table.

**Examples**

<table><thead><tr><th><strong>Id</strong></th><th><strong>Name</strong></th><th><strong>Qty</strong></th><th><strong>Price</strong></th></tr></thead><tbody><tr><td colspan="4"><code>\{\{ tablerow item in invoice.items }}</code></td></tr><tr><td><code>\{\{ item.id}}</code></td><td><code>\{\{ item.name}}</code></td><td><code>\{\{ item.quantity}}</code></td><td><code>\{\{ if item.price isPresent}}\{\{item.price}}\{\{ else }}-\{\{ endif }}</code></td></tr><tr><td colspan="4"><code>\{\{ endtablerow }}</code></td></tr></tbody></table>

***

<h2 id="6-calculations">
  6\. Calculations
</h2>

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**

| <strong>Arithmetic operations</strong> | <strong>Aggregation operations</strong> |
| -------------------------------------- | --------------------------------------- |
| %                                      | Percent                                 |
| +                                      | SUM                                     |
| \*                                     | AVERAGE                                 |
| -                                      | COUNT                                   |

The following JSON serves as input for adding calculations to the document template.

```json theme={null}
{
  "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:

| <strong>Use case</strong>                                                                                                                                                                                    | <strong>Document template</strong>                                                                                                | <strong>Output document</strong>                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| To calculate net amount from the given <em><strong>Gross Amount</strong></em> and <em><strong>Tax Amount</strong></em><br /><strong>Arithmetic calculation</strong>                                          | <strong>Net Amount:</strong><br /><code>\{\{ invoice.grossAmount + invoice.taxAmount}}</code>                                     | <strong>Net Amount:</strong><br />5211,8<br /><em><strong>Annotation:</strong></em><br /><em>5060 (grossAmount) + 151.8 (taxAmount)</em>                         |
| To calculate net amount from the given <em><strong>Gross Amount</strong></em>, <em><strong>Tax Rate</strong></em> and <em><strong>Shipping Charge</strong></em><br /><strong>Arithmetic calculation</strong> | <strong>Net Amount:</strong><br /><code>\{\{ invoice.grossAmount + invoice.taxAmount + invoice.shippingCharge}}</code>            | <strong>Net Amount:</strong><br />5226.8<br /><em><strong>Annotation:</strong></em><br /><em>5060 (grossAmount) + 151.8 (taxAmount) + 15 (shippingCharge)</em>   |
| To calculate tax amount from the given <em><strong>Tax Rate</strong></em> and <em><strong>Gross Amount</strong></em><br /><strong>Arithmetic calculation</strong>                                            | <strong>Tax Amount:</strong><br /><code>\{\{ invoice.taxRate % \* invoice.grossAmount}}</code>                                    | <strong>Tax Amount:</strong><br />151.8<br /><em><strong>Annotation:</strong></em><br /><em>3% (taxRate)  \* 5060 (grossAmount)</em>                             |
| To calculate gross amount from <em><strong>individual line item amounts</strong></em><br /><strong>Aggregation calculation</strong>                                                                          | <strong>Gross Amount:</strong><br /><code>\{\{ \$sum(invoice.items.amount) }}</code>                                              | <strong>Gross Amount:</strong><br />5060<br /><em><strong>Annotation:</strong></em><br /><em>Sum (2900+1560+600)</em>                                            |
| To calculate number of line items<br /><strong>Count calculation</strong>                                                                                                                                    | <strong>Count:</strong><br /><code>\{\{ \$count(invoice.items.amount) }}</code>                                                   | <strong>Count:</strong><br />3                                                                                                                                   |
| To calculate average of line items                                                                                                                                                                           | <strong>Average Amount:</strong><br /><code>\{\{ \$average(invoice.items.amount) }}</code>                                        | <strong>Average Amount:</strong><br />1686.66                                                                                                                    |
| To calculate net amount from the <em><strong>given Line Item Amount</strong></em>, and <em><strong>Tax Rate </strong></em><br /><strong>Arithmetic + Aggregation calculation</strong>                        | <strong>Net Amount:</strong><br /><code>\{\{ $sum(invoice.items.amount) + invoice.taxRate % * $sum(invoice.items.amount)}}</code> | <strong>Net Amount:</strong><br />5211,8<br /><em><strong>Annotation:</strong></em><br /><em>Sum (2900+1560+600) + </em><br /><em>3% \* Sum (2900+1560+600)</em> |

***

<h2 id="7-box-sign-template-tags">
  7\. Box Sign template tags
</h2>

[Box Sign template tags](/en/box-sign/templates/creating-templates-using-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.

The table below lists the tags available in the Box Doc Gen Template Creator add-in and the tagging script.

| <strong>Field</strong>       | <strong>Box Sign’s template code</strong> | <strong>Supported </strong><br /><strong>via tagging script</strong> | <strong>Supported </strong><br /><strong>via add-in</strong> |
| ---------------------------- | ----------------------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------ |
| Text field                   | <code>\[\[t\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| Date field                   | <code>\[\[d\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| Checkbox field               | <code>\[\[c\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| Signature field              | <code>\[\[s\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| Stamp field type             | <code>\[\[st\|0]]</code>                  | Yes                                                                  | Yes                                                          |
| Initials field type          | <code>\[\[i\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| Name field type              | <code>\[\[n\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| First name field type        | <code>\[\[fn\|0]]</code>                  | Yes                                                                  | Yes                                                          |
| Last name field type         | <code>\[\[ln\|0]]</code>                  | Yes                                                                  | Yes                                                          |
| Company field type           | <code>\[\[co\|0]]</code>                  | Yes                                                                  | Yes                                                          |
| Email field type             | <code>\[\[e\|0]]</code>                   | Yes                                                                  | Yes                                                          |
| Title field type             | <code>\[\[ti\|0]]</code>                  | Yes                                                                  | Yes                                                          |
| For an attachment field type | <code>\[\[a\|0]]</code>                   | Yes                                                                  | Yes                                                          |
