# Combining and nesting templating functions

With all functions that take parameters the convention is as follows:

* String literal parameters and number literal parameters are enclosed in single quotes.
* When calling a function from within a function the inner function should be enclosed in parenthesis (round brackets) not handlebars.
* When using variables and arrays, their names are string based parameters and are normally enclosed in single quotes, unless they are the result of a nested function (this can be useful)
* Boolean flag parameters are not enclosed in single quotes.
* Iterator instance parameters (this, or this.<\<some-variable>>) are not enclosed in single quotes
* Function names are not enclosed in single quotes.

#### Examples:

```handlebars
{{ putValue 'id' (Request.Body 'jsonpath' '$.id') true }}
{{ multiply '5' '2' '0.00' }}
{{ multiply this.quantity this.price '0.00' }}
```

Many functions can be nested inside other functions. In some cases it makes sense to nest multiple levels of functions. It is conventional to enclose the inner functions with round brackets instead of handlebars.

#### Example 1:

Consider the following 3 functions:

```handlebars
{{ sum <array> '<format>' }}
{{ split <delimited-string> '<delimiter>' }}
{{ Request.Body '<querylanguage>' '<query>' }}
```

As an example they can be combined together in the following way:

```handlebars
{{ sum(split (Request.Body 'jsonpath' '$.price[*]') ' ') '0.00' }}
```

#### Example 2:

Consider the following 3 functions:

```handlebars
{{ putValue '<variablename>' <value> <outputtotemplate?> }}
{{ multiply <number1> <number2> '<format>' }}
{{ csv '<data-source-name>' '<key-column>' '<key-value>' '<return-column>' }}
```

As an example they can be combined together in the following way:

```handlebars
{{ putValue 'linetotalsbeforediscounts' (multiply (this.quantity) (csv 'products' 'upc' 'this.upc' 'price') '') false}}
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloud.hoverfly.io/create-simulations/using-templating-in-simulations/combining-and-nesting-templating-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
