> For the complete documentation index, see [llms.txt](https://docs.cloud.hoverfly.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloud.hoverfly.io/create-simulations/using-templating-in-simulations/combining-and-nesting-templating-functions.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
