﻿# Template syntax

> [HTML Version](360027003711.html)

The first step in setting up document generation from a template is to prepare a file, which can be in one of the following formats: **.doc**, **.docx**, **.rtf**, **.dot**, **.dotx**, **.xls**, **.xlsx**, **.xltx**, **.xlt**. 

The file uses a special syntax and can contain variables, functions, conditions, and loops. These let you insert data from BRIX, format text, numbers, and dates, inflect values, and generate lists and tables. 

This article explains how to write variables and expressions in a template file.

After preparing the file, follow the remaining setup steps.

````
начало примера

````
Related articles:

- [Add and set up a document template](360026936731.md). Upload a template file to the system and map its variables.

- [Generate from Template](360026720792.md) and [Generate from File](generate-from-file.md). Set up automatic document generation using dedicated activities in a business process.

````
конец примера

## ````
Choose the syntax for your task

| | |
|------|------|
| **Task** | **Section to use** |
| Insert a field value | [Variable syntax](#fields_syntax) |
| Display a property of a file, user, or associated item | [Nested variable syntax](#inner_fields_syntax) |
| Learn how to write arguments | [Pass function arguments](#function-arguments) |
| Change the case or extract part of a string | [Work with text](#string-data-type) |
| Display a value of a specific type | [The ToString() function](#tostring_function) |
| Format a number | [The NumberFormat() function](#numberformat) |
| Format a date and time | [The DateTime() and Now() functions](#set-datetime-now) |
| Count rows or items | [The Count() function](#count) |
| Display text based on a field value | [Conditions](#if) |
| Display a list or generate a table | [The \{for\} loop](#cycle) |
| Insert a barcode, image, or link, or add a custom function | [Special template syntax functions](another-template-syntax-functions.md) |


## General syntax rules

### Variable syntax

To insert a variable, enclose its code in braces and prefix it with a dollar sign: `\{\$variable\_code\}`.

Variable names must be unique and use Latin characters.

````
начало примера

````
Example

`\{\$client\}`. Inserts the contractor name from the item page.

````
конец примера

### ````
Nested variable syntax

A template can access the attributes of fields in the app context using nested variables.

This is available for fields of types such as [Files](360009707032.md#file_type), [Users](360009707032.md#users), [App](app-data-type.md), [Arbitrary app](360009707032.md#arbitrary-app), and others.

To display an attribute of a linked object, separate the main field code and the nested property code with a period: `\{\$variable\_code.nested\_variable\_code\}`.

````
начало примера

````
Example

The **Orders** app has the fields **Contract** (code: `contract`) and **Client** (code: `client`), which contain links to app items. Use the following syntax:

- `\{\$contract.\_\_name\}`. Displays the name of the file uploaded to the **Contract field**.

- `\{\$client.phone\}`. Displays the phone number of the contractor specified in the **Client **field. 

````
конец примера

### ````
Pass function arguments

Pass function arguments in parentheses, separated by commas:

1. Write variables and numbers without quotation marks, for example, `\{\$sum\}`, `100`.

2. Enclose string values, such as formats, locales, masks, and text, in quotation marks, for example, `"en-US"`, `"short"`.

Although the system recognizes simple values without quotation marks, we recommend quoting all string arguments for consistency. This prevents errors when processing spaces and special characters.

The following types of quotation marks are supported: **" "**, **« »**, **“ “**, **” ”**, **' '**.

3. In syntax descriptions, optional arguments are enclosed in square brackets `\[\]`. Do not include these brackets in function calls in your template. 

### Specify a locale

Some functions, such as `ToString()`, `DateTime()`, `Now()`, accept a locale argument to display a date, number, or amount in the format used in a specific country.

Available locales: 

- `"en-US"`. English (United States).

- `"en-GB"`. English (United Kingdom).

- `"de-DE"`. German.

- `"fr-FR"`. French.

- `"es-ES"`. Spanish.

You can also use a short language code, such as `"es"` or `"en"`.

````
начало примера

````
Example 

The date value in the variable `\{\$\_\_createdAt\}` is **25.08.2000**:

`\{DateTime("DD MMMM YYYY", \{\$\_\_createdAt\}, "en-GB")\} `—> 25 August 2000.

````
конец примера

## ````
Work with text

String functions let you change text case and display part of a value.

In these examples, the variable `\{\$string\}` contains the value **John Dean**.

### Convert to uppercase with UpperCase()

**Syntax:**

`\{UpperCase(\{\$variable\_code\}: string)\}`.

````
начало примера

````
Example

`\{UpperCase(\{\$string\})\}` —> JOHN DEAN.

````
конец примера

### ````
Convert to lowercase with LowerCase()

**Syntax:**

`\{LowerCase(\{\$variable\_code\}: string)\}`.

````
начало примера

````
Example

`\{LowerCase(\{\$string\})\}` —> john dead.

````
конец примера

### ````
Capitalize the first letter with Capitalize()

This function converts the first letter of the first word to uppercase.

**Syntax:**

`\{Capitalize(\{\$variable\_code\}: string)\}`.

````
начало примера

````
Example

`\{Capitalize(\{\$string\})\}` —> John dean.

````
конец примера

### ````
Extract part of a string with Substr()

This function extracts a substring of a specified length, starting at the specified position.

**Syntax:**

`\{Substr(\{\$variable\_code\}: string, position: number, \[length: number\])\}`,

Where:

- **position**. The character position where the substring starts.

- **length**. The number of characters to display. If omitted, the function returns the rest of the string from the specified position.

````
начало примера

````
Examples

1. `\{Substr(\{\$string\}, 0, 3)\}` —> Joh.

2. `\{Substr(\{\$string\}, 3)\}` —> n Dean.

````
конец примера

## ````
Display a variable value with ToString()

The function `ToString()` displays values of the following data types in a document:

- [String](360027003711.md#string)

- [Number](#number)

- [Category](360027003711.md#string)

- [Yes/no switch](360027003711.md#yes_no)

- [Money](360027003711.md#money)

- [Full name](#name)

- [Phone number](360027003711.md#phone)

- [Date/time](#date_time)

For more information about data types, see [System data types](360009707032.md).

The available arguments depend on the variable type.

### String

The function `ToString()` displays the value of a text variable. 

**Syntax:**

`\{ToString(\{\$variable\_code\}: string)\}`

For the **String** type, this function is optional. The value also appears in the template using the standard syntax for a variable code  in braces. 

````
начало примера

````
Examples

The variable `\{\$string\}` contains the value **Sent for approval**.

1. `\{ToString(\{\$string\})\}` —> Sent for approval.

2. `\{\$string\} `—> Sent for approval.

````
конец примера

### ````
Number

By default, numbers are displayed as digits.

**Syntax:**

`\{ToString(\{\$variable\_code\}: number, \["format": string\], \["locale": string\])\}`,

Where:

- **format**. Use the format value `"astext"` to spell out an integer.

- **locale**. The language used to spell out the number, for example, `"en"`. For the available options, see [Specify a locale](#locale).

````
начало внимание

````
To spell out decimal numbers, instead of `ToString()` use `NumberToString()`.

````
конец внимание 

начало примера

````
Examples

The variable `\{\$number\}` contains the integer 546.

1. `\{ToString(\{\$number\})\}` —> 546.

2. `\{ToString(\{\$number\}, "astext")\}` —> five hundred forty six.

3. `\{ToString(\{\$number\}, "astext", "es-ES")\}` —> quinientos cuarenta y seis.

````
конец примера

````
For more control over number formatting, use [NumberFormat()](#numberformat). It lets you round the fractional part, convert a number to a percentage or hexadecimal notation, and more.

### Category

The **Category** data type lets you select one value from a predefined list. For example, a payment method can be card or cash.

When configuring this field, specify the variable name and code, and the name and code of each option.

**Syntax:**

`ToString(\{\$variable\_code\}: category)`.

You can also display the name of the selected option:

- Using the variable code: `\{\$variable\_code\}`.

- By accessing the option name with a period: `\{\$variable\_code.name\}`.

To display the code of the selected option instead of its name, use `\{\$variable\_code.code\}`.

````
начало примера

````
Example

The app contains a variable called **Payment method** (code: `\{\$payment\}`). The selected option is **by card** (code: `card`).

1. Payment is made `\{ToString(\{\$payment\})\}` —> Payment is made by card.

2. Payment is made `\{\$payment\} `—> Payment is made by card.

3. Payment is made `\{\$payment.name\} `—> Payment is made by card.

4. Selected category code: `\{\$payment.code\} `—> Selected category code: card.

````
конец примера

### ````
Yes/no switch

This data type has two options: **Yes** and **No**. You can rename them, for example, to **Approved** and **Not approved**.

**Syntax:**

`\{ToString(\{\$variable\_code\}: yes/no switch\})\}`.

````
начало примера

````
Example

For the variable **Decision** (code: `resolution`)` `the option **Yes** (code: `true`) is defined as **Approved** and selected as the field value:

Document decision: `\{ToString(\{\$resolution\})\}` —> Document decision: Approved.

````
конец примера

### ````
Money

A variable of type **Money** can be displayed in several formats.

**Syntax:**

`\{ToString(\{\$variable\_code\}: money, \["format": string\], \["locale": string\])\},`

Where:

- format. Available format values:

	- `"short"`. Short numeric format. Symbols and separators follow the selected locale—> 1 005,56.

	- `"sign" `**. **Amount with the currency code specified in the variable** **—> EUR 1 005,56;

	- `"full"`**. **Full format with the currency name** **—> 1 005 euros and 56 cents;

	- `"astext"`** **. Amount in words —> One thousand and five euros and 56 cents.

	- `"wildcard"`** **. Custom format. Replace the keyword with a quoted template using these symbols: `"%i"` for the integer part, `"%f"` for the fractional part.

Examples of custom format

1. `\{ToString(\{\$money\}, "%i eur. %f c.")\}` —> 1005 eur. 56 c.

2. `\{ToString(\{\$money\}, "%i (%f)")\}` —> 1005 (56).

3. `\{ToString(\{\$money\}, "`€ `%i %f c.")\}` —> € 1005  56 c.

- **locale**. Displays the value in a specific language, for example, `"en"` or `"es"`. For the available options, see [Specify a locale](#locale).

````
начало примера

````
Example

`\{ToString(\{\$money\}, "full", "en")\}` —> 1 005 euros 56 cents.

````
конец примера

### ````
Full name

Use `ToString()` to display a last name, first name, and patronymic in the required format and grammatical case.

**Syntax:**

`\{ToString(\{\$variable\_code\}: full name, \["format": string\], \["case": string\])\}`,

Where:

- **format**. Available values:

	- `"long"`. Displays the last name, first name, and patronymic in full.

	- `"short"`. Displays the last name and initials.

- **case (for languages where grammatical case values are applied)**. Grammatical case names are not letter case-sensitive:

	- `"Nominative"`

	- `"Genitive"` 

	- `"Dative"`

	- `"Accusative"` 

	- `"Instrumental"` 

	- `"Prepositional"`

For more control over full name formatting, use these dedicated functions:

- [FormatFio()](#format_fio). Sets the order of name parts and automatically adds a preposition in the prepositional case.

- [GetPartOfFullName()](#part_of_fio). Extracts only the first name, last name, or patronymic.

### Phone number

This function sets a mask for displaying a phone number.

**Syntax:**

`\{ToString(\{\$variable\_code\}: phone number, "mask: +7-XXX-XXX-XX-XX EEE")\}`,

The Latin letters represent:

- **X**. Main number.

- **E**. Extension.

If the number has fewer digits than the number of `X` or `E` characters in the mask, extra characters are omitted from the generated document.

The digits are inserted from left to right.

````
начало примера

````
Examples

1. `\{ToString(\{\$phone\}, "+4-XXX-XXX-XX-XX")\}` —> +4-999-345-67-89.

2. `\{ToString(\{\$phone\}, "X-XXX-XXX-XX-XX EEE")\}` —> 0-912-345-67-89 159.

3. `\{ToString(\{\$phone\}, "XX-XX-XX E")\}` —> 45-67-89 3.

````
конец примера

### ````
Date/time

Use `ToString()` to display a value of type **Date/time**, such as the equipment delivery date in a contract.

The data type **Date/time** has these subtypes: **Date/time**, **Date**,** Time**. The function result depends on the subtype selected for the variable.

**Syntax:**

`\{ToString(\{\$variable\_code\}: date/time, \["format": string\], \["locale": string\])\}`,

Where:

- **format**. Controls the level of detail and how date and time components are displayed, depending on the subtype:

	- No format specified. Displays the date using the numeric mask DD.MM.YYYY and the time including seconds as hh:mm:ss.

	- `"short"`. Short format. Displays the date numerically and omits seconds from the time.

	- `"long"`. Long format. Spells out the month name and includes seconds in the time.

- **locale**. The date follows the conventions of the specified country, for example, `"en"` or `"es"`. For all available options, see [Specify a locale](#locale).

**Important:** the **Date/time** subtype displays the date and time using the company time zone. With the **Date** and **Time** subtypes, values are displayed as stored in the system, without time zone adjustments.

````
начало примера

````
Examples

The variable `\{\$date\}` stores the value **09.04.2025 15:18:43**. 

1. No format specified: `\{ToString(\{\$date\})\}`:

	- Subtype **Date/time** —> 09.04.2025 15:18:43;

	- Subtype **Date** —> 09.04.2025;

	- Subtype **Time** —> 15:18:43.

2. Short format without seconds: `\{ToString(\{\$date\}, "short")\}`:

	- Subtype **Date/time** —> 09.04.2025 15:18;

	- Subtype **Date** —> 09.04.2025;

	- Subtype **Time** —> 15:18.

3. Long format with the month name spelled out: `\{ToString(\{\$date\}, "long")\}`: 

	- Subtype **Date/time **—> 09.04.2025 15:18:43;

	- Subtype **Date** —> 9 April 2025;

	- Subtype **Time** —> 15:18:43.

4.  With a locale specified: `\{ToString(\{\$date\}, "short", "en-US")\}`:

	- Subtype **Date/time **—> 4/9/25 3:18 pm;

	- Subtype **Date** —> 4/9/25;

	- Subtype **Time** —> 3:18 pm.

````
конец примера

````
For more control over date and time formatting, use [DateTime()](#datetime-function). It lets you define a custom display mask, for example, to reorder components or show the day of the week.

## Format a number with NumberFormat()

The function `NumberFormat()` displays a variable of type **Number** in a specific format, for example, with a fixed number of decimal places or in hexadecimal notation.

**Syntax:**

`\{ToString(\{\$variable\_code\}: number, \["format": string\])\}`.

The format in `NumberFormat()` is a letter that specifies how the number is displayed. You can add a precision specifier, a number immediately after the letter. Depending on the format, it sets the number of decimal places or the minimum display length.

In these examples, the variable `\{\$number\}` contains the decimal number **1125,34**.

### Decimal format

The argument `"D"` or `"d"` displays an integer without a fractional part and pads it with zeros to the specified length. The precision specifier sets the number of padding zeros.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "D5")\}` —> 01125.

````
конец примера

### ````
Exponential format

The argument `"E"` or `"e"` displays the number as a mantissa and exponent. The precision specifier sets the number of decimal places.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "E2")\}` —> 1.13E+03.

````
конец примера

### ````
Fixed-point format

The argument `"F"` or `"f"` displays a fixed number of decimal places.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "F2")\}` —> 1125.34.

This example specifies two decimal places.

````
конец примера

### ````
General format

The argument `"G"` or `"g"` converts the number to fixed-point or exponential notation, whichever is shorter. The precision specifier sets the number of digits without padding zeros.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "G4")\}` —> 1125.

````
конец примера

### ````
Numeric format with separators

The argument `"N"` or `"n"` displays the number with digit grouping separators. The precision specifier sets the number of decimal places.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "N3")\}` —> 1,125.340.

````
конец примера

### ````
Percentage format

The argument `"P"` or `"p"` multiplies the number by 100 and adds the percent sign **%**.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "P")\}` —> 112534.00 %.

````
конец примера

### ````
Round-trip format

The argument `"R"` or `"r"` displays an exact representation of the number without rounding. Precision specifiers are not supported.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "R")\}` —> 1125.34.

````
конец примера

### ````
Hexadecimal format

The argument `"X"` or `"x"` displays the number in hexadecimal notation without a fractional part.

````
начало примера

````
Example

`\{NumberFormat(\{\$number\}, "X")\}` —> 465.

````
конец примера

## ````
Format a date and time 

### The DateTime() function

The function `DateTime()` displays a date and time using the specified format and locale, for example, an item’s creation date.

**Syntax:**

`\{DateTime("format": string, \{\$variable\_code\}: date/time, \["locale": string\])\}`, 

Where:

- **format**. A date and time display mask such as `"DD MM YYYY hh:mm:ss"`. 

Quotation marks delimit the format and individual date components within the mask.

Available day and time mask formats



For example, the date value is 02.01.2025 15:04:05 (Thursday):

- Month:

	- `"M"`. 1;

	- `"MM"`. 01;

	- `"MMM"`. JAN;

	- `"MMMM"`. January;

- Day:

	- `"D"`. 2;

	- `"DD"`. 02;

	- `"DDD"`. MON;

	- `"DDDD"`. Monday;

- Year:

	- `"YY"`. 25;

	- `"YYYY"`. 2025;

- Hours: `"hh"`. 15

- Minutes: `"mm"`. 04

- Seconds: `"ss"`. 05.



- **locale**. The date follows the conventions of the specified country, for example, `"ru"` or `"en"`. For all available options, see [Specify a locale](#locale).

````
Начало примера

````
Examples

The variable `\{\$\_\_createdAt\}` contains the value **31.08.2024 08:30:56**:

`\{DateTime("'DD' MMMM YYYY",\{\$\_\_createdAt\},"en\_US")\}` —> '31' August 2024.

````
Конец примера

### ````
The Now() function

The function `Now()` inserts the current date and time into the template using the time zone and locale.

**Syntax:**

`\{Now(\["format": string\], \["locale": string\], \["time\_zone": string\])\}`, 

Where:

- **format**. The date and time display format:

	- `"short"`. Date and time without seconds. Used by default if no format is specified.

	- `"date"`. Numeric date only.

	- `"datelong"`. Date with the month name spelled out.

	- `"time"`. Time in hours and minutes only.

	- `"timelong"`. Time including seconds.

- **locale**. Month names and the date format in the required language, for example, `"en"`, `"es"`. For all available options, see [Specify a locale](#locale).

- **time zone**. The time zone name in the standard **IANA**, for example, `"America/Toronto"`.

````
начало примера

````
Examples

Suppose the current date and time in your location is **13.04.2025 15:34**:

1. `\{Now()\}` —> 13.04.2025 15:34. 

With no arguments, the function displays the date and time in the short format `"short"`, using the locale and time zone configured in the system. 

2. `\{Now("date", "en")\}` —> 04/13/2025.

3. `\{Now("datelong", "en-US")\}` —> April 13, 2025.

4. `\{Now("timelong", "en", "America/Toronto")\}` —> 08:34:22. The result uses the Toronto time zone (EDT).

````
конец примера

## ````
Count items with Count()

The function `Count()` returns the number of items passed to a variable of the [Table](360009707032.md#table) or [App](app-data-type.md) type.

Use this function to:

- Display the number of nested items in a linked app.

- Display the total number of table rows.

- Count items in nested tables.

**Syntax:**

`\{Count(\{\$variable\_code\}: app or table)\}`.

````
Начало примера

````
Examples

1. Count rows in a report table: 

`\{Count(\{\$report\_table\})\}` —> 12.

2. Count items in a linked app:

`\{Count(\{\$app\})\}` —> 3. 

````
Конец примера

### ````
Use Count() in \{for\} loops

The function `Count()` can be used inside a [\{for\} loop](#cycle) to count items in nested tables or nested relationships.

#### Display the number of rows in a nested table

If a row in the main table contains another table, such as a list of completed tasks, use this syntax:

````
\{for row in \{\$report\_table\}\}  
 Subrow count: \{Count(\{\$row.execution\})\}  
\{end\}

````
Where:

- `\{\$report\_table\}`. Main report table.

- `\{\$row.execution\}`. A nested variable of type **Table** in a table row.

#### Display the number of rows in an associated app’s table

Use this expression:

````
\{for row in \{\$app\}\}  
 Subrow count: \{Count(\{\$row.multi\})\}  
\{end\}

````
Where:

- `\{\$app\}`. A variable of type **App** that references the associated app.

- `\{\$row.multi\}` . A variable of type **Table** in that app’s context.

### The FormatFio() function

Function `FormatFio()` inflects a full name in the specified grammatical case and displays its parts in the specified order, for languages where it applies.

**Syntax:**

`\{FormatFio(value: "string" or \{\$variable\_code\}: full name, \["case": string\], \["format": string\])\}`,

Where:

- **value**. Specify a quoted string or a variable of type **Full name**. 

- **case**. Not letter case-sensitive. 

	- `"Nominative"` | 

	- `"Genitive"` | 

	- `"Dative"` |

	- `"Accusative"` 

	- `"Instrumental"` .

	- `"Prepositional"`

- **format**. A quoted mask for displaying a full name. It lets you reorder the parts and display them in full or as initials, with or without spaces. The mask is not case-sensitive; the result uses initial capitals: 

	- `"Surname"`

	- `"Name"`

	- `"Middle name"` 

````


### ````
The GetPartOfFullName() function

The function `GetPartOfFullName()` or returns a full name or one of its parts. 

**Syntax:** 

`\{GetPartOfFullName("value": string or \{\$variable\_code\}: full name, "name part": string)\}`, 

Where:

- **value**. Specify a quoted string or a variable of type **Full name**.

- **name part**. The full or abbreviated name of the part to return:

	- `"Surname"` 

	- `"Name"` 

	- `"Middle name"` 

	- `"Full name"` 

````
начало примера

````
Examples

The value **Jennifer Maria Garden** is passed to the function as a string and using the variable `\{\$fullname\}`:

`\{GetPartOfFullName("Jennifer Maria Garden", "")\}` —> Maria.

````
конец примера

#### ````
Another way to access name parts

If the data is stored in a variable of type **Full name**, you can retrieve name parts without functions. Specify the variable code followed by a period and the required property:

- `\{\$variable\_code.lastname\}`. Last name.

- `\{\$variable\_code.firstname\}`. First name.

- `\{\$variable\_code.middlename\}`. Middle name.

````
начало примера

````
Example

A variable of type **Full name** with the code `\{\$user\}` contains the value **Jennifer Maria Garden**.

`\{\$user.lastname\}` —> **Garden**.

````
конец примера

## ````
Display text conditionally

Conditions display text in a document based on a variable value or whether a field contains data.

Syntax: 

`\{if condition\} text \{else\} alternative text \{end\}`, 

Where: 

- **condition**. A logical expression to evaluate, in the form `\{\$variable\_code\} operator value`:

	- **operator**. A comparison operator: equal to, not equal to, greater than, less than, and so on.

	- **value**. A quoted string or a number.

- **text**. The content displayed in the document if the condition is met.

- **\{else\} alternative text**. Optional. The content displayed if the condition is not met.

Available operations for evaluating conditions

You can use the following operators in conditions:

- `=`** **. Equal to.

- `<>`. Not equal to.

- `>`. Greater than.

- `>=`. Greater than or equal to.

- `<`. Less than.

- `<=`. Less than or equal to.

### Check a single value

````
начало примера

````
Example

````
\{if \{\$user\_name\} = "Daria Green"\} Best regards, Daria Green \{end\}

````
If the field value matches the specified value, the document displays “Best regards, Daria Green”.

````
конец примера

### ````
Display one of two alternatives

````
начало примера

````
Example

````
\{if \{\$week.day\} = "Friday"\}  
Have a great weekend\!  
\{else\}  
Goodbye\!  
\{end\} 

````
The text displayed depends on the current day of the week.

````
конец примера

### ````
Check a Yes/no switch field

For variables of type **Yes/no switch**, use the values from the **Options** field in the condition. The defaults are **Yes** and **No**.

````
начало примера

````
Example

````
\{if \{\$options\} <> "No"\} Payment completed \{end\}

````
The text is displayed if the selected option is **Yes**.

````
конец примера

### ````
Check whether a field has a value

A condition can check whether an app item property contains a value.

````
начало примера

````
Example

````
\{if \{\$document\}\} \{\$document\} \{end\}

````
If a document is uploaded to a field of type **Files**, its name appears in the generated file.

````
конец примера

````
**Important:** for properties of type **App** or **Files**, the condition applies when the **One** option is enabled. If multiple items are allowed, use [The \{for\} loop](#cycle).

### Conditions in Excel

When writing conditions in **.xlsx** files, place the `\{if condition\}`, `\{else\}` and `\{end\}` operators in separate table rows containing no other data.

During document generation, the rows containing these operators are deleted entirely. Any text or values in adjacent cells in those rows are deleted as well.

````
начало примера

````
Example layout in Excel



| | |
|------|------|
| **Cell A1** | **Cell B1** |
| ````<br>\{if \{\$status\} = "Approved"\}<br>```` | ````<br> |
| Contract details | Amount: USD 100,000 |
| ````<br>\{end\}<br>```` | ````<br> |




In the generated document, the rows containing `\{if\}` and `\{end\}` are deleted, while the data row stays in place.

````
конец примера

### ````
Complex conditions with OR and AND

Use logical operators to combine multiple checks in one expression:

- `OR`. The condition is met if at least one expression is true.

- `AND`. The condition is met only if all expressions are true.

#### Example using OR

````
начало примера

\{if \{\$trip.location\_type\} = "Hotel" OR \{\$trip.location\_type\} = "Apartment"\}  
 Accommodation expenses will be reimbursed after the business trip report is reviewed.  
\{end\}

````
Depending on the accommodation type, the document displays a notice about reimbursement of additional expenses.

````
конец примера

#### ````
Example using AND

````
начало примера

\{if \{\$business\_trip\_request.isApproved\} AND isPurchased\}\}  
 The business trip is scheduled for \{\$business\_trip\_request.date\}.  
\{else\}  
 The business trip has not been scheduled yet.  
\{end\}

````
The business trip date appears if all conditions are met: the request is approved and the tickets are purchased. Otherwise, the document states that the trip has not been scheduled.

````
конец примера

#### ````
Combine OR and AND

You can combine several operators in one expression. Use parentheses to set the order in which conditions are evaluated.

````
начало примера

\{if \{\$business\_trip\_request.location\_type\} = "Hotel" OR \{\$business\_trip\_request.location\_type\} = "Apartment")  
AND (\$business\_trip\_request.price\} < 5 000)  
 \{\$business\_trip\_request.city\}  
\{end\} 

````
The city is displayed based on the accommodation type and the amount requested for accommodation.

````
конец примера

## ````
Display a list or generate a table with a \{for\} loop

The loop `\{for\}` displays a list in the document, for example, a list of [app items](#app-cycle) or multiple [files and images](another-template-syntax-functions.md#pasteimage).

**Syntax:**

````
\{for item in list\}  
 actions on item  
\{end\}````
 

Where:

- **item**. A temporary container variable. Each iteration places the next object from the list in this variable. You can choose any name, such as `item`, `row`, `position`, and then use it inside the loop to access the current object or its properties.

- **list**. A system variable from the app or business process context containing an array of data, such as apps, files, or table rows, to display sequentially in the document.

- **actions on item**. The loop body, such as text, properties, functions, or table rows, repeated for every object in the list.

````
Начало примера

````
Example displaying multiple products

The app contains a variable called **Product** of type **App (multiple)** with the code `item`. To list the ordered products, use:

````
\{for position in \{\$item\}\}  
 Product ordered: \{\$position\}  
\{end\}

конец примера

### ````
Display data as a list

The loop `\{for\}` can retrieve data from a linked app when the field is set to **Multiple**.

App item field codes can use the prefix `data` or omit it:

- `\{\$data.appListField\}`

- `\{\$appListField\}`

#### Create a \{for\} loop for a list in Word

In **.doc** or **.docx** files, data from a linked app can appear as a list or consecutive text blocks.

````
начало примера

````
Example

````
\{for app in \{\$appListField\}\}  
 App: \{\$app\}, named \{\$app.\_\_name\}, with an amount of \{\$app.money\}  
\{end\}

конец примера

#### ````
Create a \{for\} loop for a list in Excel

In **.xlsx** files, the loop displays linked app data row by row.

````
начало примера

````
Example

`\{for app in \{\$appListField\}\}`

| | | |
|------|------|------|
| `\{\$app\}` | `\{\$app.\_\_name\}` | `\{\$app.money\}` |


`\{end\}`

````
конец примера

````
**Important:** the operators `\{for\}` and `\{end\}` must be placed in separate table rows with no other data, as when[ writing \{if\} conditions](#if-for-in-excel). Otherwise, the entire row is deleted along with the operator. This does not apply to text in [merged cells](#merged-cells).

### Display data in a table

A loop can display data in a table as well as a list.

When [uploading the template to the system](360026936731.md#add_variables), set the data type of the loop variable to [Table](360009707032.md#table).

#### Create a \{for\} loop for a table in Word

To generate a table in a file of type **.doc** or **.docx**:

1. Separate the first row of the table using the **Split Table**.

2. In the blank line that appears, declare the loop `\{for\}`.

3. In the table, enter variables with the prefix `row.data` or `row`, for example, from the business process context.

4. Below the table, close the loop using `\{end\}`.

Example template:

**(template_table_doc.png)**

#### Create a \{for\} loop for a table in Excel

To display data from a BRIX table, such as a product list with quantities and prices:

1. Enter the `\{for\}` and `\{end\}` commands in the first column of the table.

2. Enter app field codes with the prefix `row.data` or `row`. The prefix accesses an item inside the loop and creates as many rows in the document as there are filled rows in the BRIX table.

Rows containing the operators `\{for\}` and `\{end\}` must not contain other text, just as when[ writing \{if\} conditions](#if-for-in-excel). Otherwise, the entire row is deleted along with the operator. This does not apply to text in [vertically merged cells](#merged-cells).

Example template layout:

**(template-syntax-2.png)**

A `\{for\}` loop can include an `\{if\}` condition. For an example, see [Configure approval and acknowledgment sheet templates](ready-made-sheets-settings.md).

Do not place multiple generated tables horizontally next to each other in a template: parallel `\{for\}` loops are not processed.

You can create a nested table and then combine several tables into one, for example, using the [Script](360027203731.md) activity in a business process. The combined table is then used to generate a document from the template.

### Nested tables

The loop `\{for\}` can create a nested table.

To access nested table columns, use a different prefix instead of `row.data` or `row`:

- `subrow.data`

- `subrow`

**(for-brix-00.PNG)**

Rows containing the operators `\{for\}` and `\{end\}` must not contain other text, as it is deleted during generation. Vertically merged cells are an exception. For example, the value `\{\$row.author\}` appears in the table when you use this template:

**(for-brix-01.PNG)**

### Display row numbers in a table

To display a row number in a table, use the prefix `row.data` or `row` and the system index property: `\{\$row.\_\_index\}`.

Example table template with row numbers, product names, and prices:

**(template_syntax-5.png)**

## Special functions

Dedicated functions are available for specific tasks:

- `GenerateBarcode()`. Display a value as a barcode.

- `JobPosition()`. Insert a user’s job title.

- `PasteImage()`. Insert an image.

- `Hyperlink()`. Convert a value to a hyperlink.

- `ExtText()`. Create a custom function for advanced template operations.

For syntax and examples, see [Special template syntax functions](another-template-syntax-functions.md).

## Example: configure a contract template

This example shows how to configure automatic generation of a supply contract:

1. ## Create a template file and add variables and functions. Use the format .docx or .xlsx. To view the file used in this example, [download it to your computer](doc_template.docx).

2. ## [Add the template to the app](360026936731.md) and map its variables to fields.

**(dt5.png)**

3. Configure a business process. To generate the file automatically, add the [Generate from template](360026720792.md) activity to the diagram and select the template you created in its settings.

4. Once a user fills out the app item form and the process reaches the generation step, the final file is created.  
**[![6.PNG](360027289212-6.PNG)]**