> For the complete documentation index, see [llms.txt](https://support.attackforge.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.attackforge.com/app/modules/reporting/template-functions.md).

# Template - Functions

## Overview

Template functions add logic to your ReportGen templates. Use them to count, total and compare data, build your own lists, sort, loop over ranges of numbers or dates, add hyperlinks, and debug your template.

Help, examples and tips are also on the [ReportGen GitHub support site](https://github.com/AttackForge/ReportGen).

<figure><img src="https://372186556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8s1QY2Q6YTHB4a6DMu%2Fuploads%2FJtaoe26Ou7BN6zgKoHXp%2Ftemplate-functions-at-a-glance.svg?alt=media&amp;token=20335991-8391-4fe8-b7fe-521679aed9a5" alt=""><figcaption></figcaption></figure>

## How to call a function

| Form                      | Use it to                                                                | Example                         |
| ------------------------- | ------------------------------------------------------------------------ | ------------------------------- |
| `{$function[...]}`        | Run a function, or print its result                                      | `{$value[myVariable]}`          |
| `{#$function[...]}...{/}` | Show what's inside only if the function is true, or loop over its result | `{#$isFirst}VULNERABILITIES{/}` |
| `{^$function[...]}...{/}` | Show what's inside only if the function is false                         | `{^$isLast}, {/}`               |

## All functions

| Group                      | Function                              | What it does                                       |
| -------------------------- | ------------------------------------- | -------------------------------------------------- |
| **Variables**              | `$declare`                            | Creates a variable                                 |
|                            | `$assign`                             | Gives a variable a new value                       |
|                            | `$append`                             | Adds data to the end of a variable                 |
|                            | `$value`                              | Gets a variable's value                            |
| **Maths**                  | `$increment`                          | Adds to a number                                   |
|                            | `$decrement`                          | Subtracts from a number                            |
|                            | `$multiply`                           | Multiplies a number                                |
|                            | `$percentage`                         | Gets the percentage of two numbers                 |
| **Lists and dictionaries** | `$push`                               | Adds a value to the end of a list                  |
|                            | `$keys`                               | Gets a dictionary's keys and values                |
|                            | `$sort`                               | Sorts a variable                                   |
|                            | `$includes`                           | Checks if a value is, or isn't, in a variable      |
| **Comparisons**            | `$equals`                             | Checks if a variable equals a value                |
|                            | `$equalsRegExp`                       | Checks a variable against a regular expression     |
|                            | `$lessThan`, `$lessThanOrEqual`       | Checks if a number or date is less than a value    |
|                            | `$greaterThan`, `$greaterThanOrEqual` | Checks if a number or date is greater than a value |
|                            | `$dateDiff`                           | Gets the difference between two dates              |
| **Loops and ranges**       | `$index`                              | Prints the current loop index                      |
|                            | `$isFirst`, `$isLast`                 | Checks if a loop is on its first or last item      |
|                            | `$range`                              | Loops over a range of numbers                      |
|                            | `$dateRange`                          | Loops over a range of dates                        |
| **Output and debugging**   | `@$hyperlink`                         | Creates a hyperlink                                |
|                            | `$comment`                            | Adds a comment that won't appear in the report     |
|                            | `$help`                               | Prints data and variables to the browser console   |

## Why it matters

* **Reports that think.** Count findings, show a heading only when there's something under it, and group data the way your readers need.
* **Less manual editing.** Totals, percentages and lists are worked out every time the report is generated.
* **Easier debugging.** `$help` shows exactly what data your template can use.

## Who uses it

| Who                                  | To                                                   |
| ------------------------------------ | ---------------------------------------------------- |
| **Report template authors**          | Add logic, totals, grouping and sorting to templates |
| **Developers and integration teams** | Build advanced templates for automated reports       |

## Variables and scope

Most functions take variables, scope, or both.

### Variables

Variables are declared with `$declare`, and referenced as `"$(variable)"`.

**Example — assigning one variable from another**

```
{$declare[Variable1][25]}
{$declare[Variable2]["$(Variable1)"]}
Value of Variable2 is 25:
{$value[Variable2]}
```

**Example — comparing two variables**

```
{$declare[Variable1][25]}
{$declare[Variable2][30]}
Check if Variable1 is greater than Variable2
{#$greaterThan[Variable1]["$(Variable2)"]}
True
{/}
```

**Dynamic variables** are used when a variable's name isn't known until the report is generated. For example, `{$declare[SomeVariable]["Ninja"]}` followed by `{$declare["$(SomeVariable)"]["Warrior"]}` translates to `{$declare[Ninja]}`, because "Ninja" is the value of `SomeVariable`.

### Scope

Scope is a relative path to a key in the ReportGen JSON data, written as `%(pathToScopeItem)`.

* Go up a level with `../`.
* Go down a level with a dot (`.`).
* Use `$help` to see the data available at any point.

<figure><img src="https://372186556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8s1QY2Q6YTHB4a6DMu%2Fuploads%2FPzGWFZTfGq1n3MjcNzeh%2Fimage.png?alt=media&amp;token=c295743b-67d5-47fa-904b-6c77213e80aa" alt=""><figcaption></figcaption></figure>

**Diagnostic help for scope**

```
{$help[scope]}
```

```
{#vulnerabilities}
{$help[scope]}
{/}
```

**Example 1 — accessing the current scope.** Prints an asset name from inside the `affected_assets` loop:

```
{#vulnerabilities}
{#affected_assets}
{$value["%(asset)"]}
{/}{/}
```

Prints the whole affected asset, instead of one key:

```
{#vulnerabilities}
{#affected_assets}
{$value["%(./)"]}
{/}{/}
```

**Example 2 — accessing the parent scope.** Prints the vulnerability's priority, one level up from the loop:

```
{#vulnerabilities}
{#affected_assets}
{$value["%(../priority)"]}
{/}{/}
```

Prints the parent vulnerability:

```
{#vulnerabilities}
{#affected_assets}
{$value["%(../)"]}
{/}{/}
```

**Example 3 — accessing a parent several levels up.** Prints the project name, two levels up:

```
{#vulnerabilities}
{#affected_assets}
{$value["%(../../project.name)"]}
{/}{/}
```

**Example 4 — accessing arrays.** Prints a value from an array of objects, using its index:

```
{#vulnerabilities}
{#affected_assets}
{$value["%(../../projectCustomFields[1].out_of_scope)"]}
{/}{/}
```

The JSON for this example:

```
"projectCustomFields":
    [
        {
            "source_ips": "192.168.0.1"
        },
        {
            "out_of_scope": "URL1, URL2, URL3"
        }
    ],
```

**Example 5 — accessing array length.** Prints the number of assets in the project's scope:

```
{$value["%(testing_summary.assets.length())"]}
```

## Variable functions

### $declare

Declares a variable, which you can then use in the other functions.

```
{$declare[variable][value]}
```

| Parameter    | Description                                                                                                                                                                                                                           |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. Supports variables and dynamic variables.                                                                                                                                                                        |
| **value**    | The value to give it. Supports booleans, integers, "strings", an empty array, a Dictionary (a flat list of key:value pairs), variables, scope, `this` (the current scope) and `this[number]` (an array element of the current scope). |

**Examples**

Declare `myVariable` with the value 0:

```
{$declare[myVariable][0]}
```

Declare `myVariable` with the value false:

```
{$declare[myVariable][false]}
```

Declare `myVariable` as an empty list (array):

```
{$declare[myVariable][[]]}
```

Add a new key `key1` to a Dictionary `myVariable`, with an empty list as its value:

```
{$declare[myVariable][<Dictionary>]}
{$declare[myVariable["key1"]][[]]}
```

Add a new key to a Dictionary `myVariable`, named from another variable `otherVariable`, with an empty list as its value:

```
{$declare[myVariable][<Dictionary>]}
{$declare[myVariable["$(otherVariable)"]][[]]}
```

### $assign

Gives a variable a new value.

```
{$assign[variable][value]}
```

| Parameter    | Description                                                                                         |
| ------------ | --------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. Supports variables and dynamic variables.                                      |
| **value**    | The new value. Supports booleans, integers, "strings", variables, scope, `this` and `this[number]`. |

**Example 1** — count the affected assets for each vulnerability, then reset the count:

```
{$declare[CountAllAffectedAssets][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[CountAllAffectedAssets][1]}
{/}
Total affected assets for vulnerability {title}:
{$value[CountAllAffectedAssets]}
{$assign[CountAllAffectedAssets][0]}
{/}
```

**Example 2 — assigning to a Dictionary:**

```
{$declare[VulnsCountAffectedAssets][<Dictionary>]}
{#vulnerabilities}
{$declare[VulnsCountAffectedAssets[“%(title)”]][0]}
{$assign[VulnsCountAffectedAssets[“%(title)”]][“%(affected_assets.length)”]}
{/}
{#$keys[VulnsCountAffectedAssets]}
Vulnerability Title: {this[0]} – Total Affected Assets: {this[1]}
{/}
```

### $append

Adds data to the end of an existing variable.

```
{$append[variable][value]}
```

| Parameter    | Description                                                                    |
| ------------ | ------------------------------------------------------------------------------ |
| **variable** | The variable's name. See `$declare`.                                           |
| **value**    | The value to add. Supports booleans, integers, "strings", variables and scope. |

**Example:**

```
{$declare[VulnTitle]["Title: "]}
{#vulnerabilities[0]}
{$append[VulnTitle]["%(./)"]}
{/}
{$value[VulnTitle]}
```

### $value

Gets a variable's value.

```
{$value[variable]}
```

| Parameter    | Description                                                           |
| ------------ | --------------------------------------------------------------------- |
| **variable** | The variable's name. Supports variables, dynamic variables and scope. |

**Example:**

```
{$declare[CountAllAffectedAssets][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[CountAllAffectedAssets][1]}
{/}
Total affected assets for vulnerability {title}:
{$value[CountAllAffectedAssets]}
{$assign[CountAllAffectedAssets][0]}
{/}
```

## Maths functions

### $increment

Adds a number to a variable that holds a number.

```
{$increment[variable][number]}
```

| Parameter    | Description                                                                                    |
| ------------ | ---------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. Supports variables and dynamic variables.                                 |
| **number**   | The amount to add. Supports integers, variables that are integers, and scope in number format. |

**Example** — count all vulnerabilities:

```
{$declare[CountTotalVulnerabilities][0]}
{#vulnerabilities}
{$increment[CountTotalVulnerabilities][1]}
{/}
```

### $decrement

Subtracts a number from a variable that holds a number.

```
{$decrement[variable][number]}
```

| Parameter    | Description                                                                                                                                                                             |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. Supports variables and dynamic variables. For example, `{$decrement["$(SomeVariable)"][1]}` translates to `{$decrement[Ninja][1]}` when `SomeVariable` is "Ninja". |
| **number**   | The amount to subtract. Supports integers, variables that are integers, and scope in number format.                                                                                     |

**Example** — count all vulnerabilities except Info:

```
{$declare[CountAllVulnsExceptInfo][0]}
{#vulnerabilities}
{$increment[CountAllVulnsExceptInfo][1]}
{#priority === "Info"}
{$decrement[CountAllVulnsExceptInfo][1]}
{/}{/}
```

### $multiply

Multiplies a variable that holds a number.

```
{$multiply[variable][number]}
```

| Parameter    | Description                                                                                                                 |
| ------------ | --------------------------------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. See `$declare`.                                                                                        |
| **number**   | The number to multiply the variable's value by. Supports integers, variables that are integers, and scope in number format. |

**Example:**

```
{$declare[AmountToCharge][500]}
{#projectCustomFields}
{#rateToMultiplyCharge}
{$multiply[AmountToCharge][”%(rateToMultiplyCharge)”]}
{/}{/}
{$value[AmountToCharge]}
```

### $percentage

Gets the percentage of two numbers.

```
{$percentage[variable][number]}
```

| Parameter    | Description                                                                                                |
| ------------ | ---------------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. See `$declare`.                                                                       |
| **number**   | The number to compare against. Supports integers, variables that are integers, and scope in number format. |

**Example 1 — percentage of Value divided by TotalValue:**

```
{$declare[TotalValue][100]}
{$declare[Value][25]}
{$percentage[Value]["$(TotalValue)"]}%
```

**Example 2 — rounded up:**

```
{$declare[TotalValue][47]}
{$declare[Value][25]}
{$percentage[Value]["$(TotalValue)"] | roundUp}%
```

**Example 3 — to 2 decimal places:**

```
{$declare[TotalValue][47]}
{$declare[Value][25]}
{$percentage[Value]["$(TotalValue)"] | toFloat:'2'}%
```

## List and dictionary functions

### $push

Adds a value to the end of a variable that was declared as a list (array).

```
{$push[variable][value]}
```

| Parameter    | Description                                                                                                                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. See `$declare`. Supports variables and dynamic variables. For example, `{$declare[SomeVariable]["Ninja"]}` then `{$push["$(SomeVariable)"]["test"]}` translates to `{$push[Ninja]}`. |
| **value**    | The value to add to the end of the list. Supports strings, integers, variables, scope, `this` and `this[number]`.                                                                                         |

**Example 1** — make a variable holding each affected asset for *SSL Weak Cipher* vulnerabilities, based on custom tags. Combine with `$value` to get the affected assets.

```
{$declare[WeakCipherVulns][[]]}
{#vulnerabilities | filterBy:“AffectedAssetCustomTags”:[“ssl_weak_ciphers:true”]}
{$push[WeakCipherVulns][“%(./)”]}
{/}
{#$value[WeakCipherVulns]}
Weak Cipher Vulnerability Title: {title}
{/}
```

**Example 2 — pushing to a Dictionary.** Push data to a Dictionary, and use `$keys` to show it:

```
{$declare[TestingPhaseVulns][<Dictionary>]}
{#projectCustomFields}
{#testing_phases}
{$declare[CurrentPhase][“%(./)”]}
{$declare[TestingPhaseVulns[“$(CurrentPhase)”]][[]]}
{#vulnerabilities | filterBy:“AffectedAssetCustomFields”:[“testing_phase:$(CurrentPhase)”]}
{$push[TestingPhaseVulns[“$(CurrentPhase)”]][“%(./)”]}
{/}{/}{/}
{#$keys[TestingPhaseVulns]}
Vulnerabilities for Testing Phase: {this[0]}
{#this[1]}
Vulnerability Title: {title}
{/}{/}
```

### $keys

Gets a Dictionary's keys and values, as a list of key and value pairs. Use `this[0]` for the key and `this[1]` for the value.

```
[
    [
        "key",
        "value"
    ]
]
```

**Example 1:**

```
{$declare[VulnsCountAffectedAssets][<Dictionary>]}
{#vulnerabilities}
{$declare[VulnsCountAffectedAssets[“%(title)”]][0]}
{$assign[VulnsCountAffectedAssets[“%(title)”]][“%(affected_assets.length)”]}
{/}
{#$keys[VulnsCountAffectedAssets]}
Vulnerability Title: {this[0]} – Total Affected Assets: {this[1]}
{/}
```

**Example 2:**

```
{#vulnerabilities}
{#$keys[this]}
{$help[scope]}
Key: {this[0]}
Value: {this[1]}
{/}{/}
```

### $sort

Sorts the data in a variable.

```
{#$sort[variable]["key:<asc/desc>"]}{/}
```

| Parameter | Description                                                                           |
| --------- | ------------------------------------------------------------------------------------- |
| **key**   | The JSON object key. Leave it out when sorting a list of strings, but keep the colon. |
| **asc**   | Sorts in ascending order.                                                             |
| **desc**  | Sorts in descending order.                                                            |

**Example 1 — sort a list:**

```
{#$sort[UniqueAffectedEndpoints][":asc"]}{/}
```

**Example 1 — single-key sort:**

```
{#$sort[UniqueAffectedEndpoints]["af_sys_affected_endpoint:desc"]}{/}
```

**Example 2 — multi-key sort:**

```
{#$sort[UniqueOWASPTop10Vulns]["priority:asc","title:desc"]}{/}
```

### $includes

Checks whether a value is in a variable, or isn't (excludes).

To check if data exists:

```
{#$includes[variable][value]}{/}
```

To check if data doesn't exist (excludes):

```
{^$includes[variable][value]}{/}
```

**Example 1** — make a unique list of affected asset names, then print it:

```
{$declare[UniqueAssets][[]]}
{#vulnerabilities}
{#affected_assets}
{^$includes[UniqueAssets]["%(asset)"]}
{$push[UniqueAssets]["%(asset)"]}
{/}{/}{/}
{#$value[UniqueAssets]}
{.}
{/}
```

**Example 2** — check whether a Dictionary "Evidence" has a key "POC" that includes a given proof of concept.

<pre><code>{$declare[UniquePOCs][[]]}
{#affected_assets}
{^$includes[UniquePOCs][“%(proof_of_concept_raw)”]}
{$push[UniquePOCs][“%(proof_of_concept_raw)”]}
{/}{/}{/}
{#$value[UniquePOCs]
{$declare[Evidence][&#x3C;Dictionary>]}
<strong>{$declare[Evidence["POC"]]["%(./)"]}
</strong>{#affected_assets}
{^$includes[Evidence["POC"]][“%(proof_of_concept_raw)”]}
{$push[Evidence["POC"]][“%(proof_of_concept_raw)”]}
{/}{/}{/}
</code></pre>

## Comparison functions

### $equals

Checks whether a variable equals a value.

```
{$equals[variable][value]}
```

| Parameter    | Description                                                                                |
| ------------ | ------------------------------------------------------------------------------------------ |
| **variable** | The variable's name. Supports variables and dynamic variables.                             |
| **value**    | The value to compare against. Supports booleans, integers, "strings", variables and scope. |

**Example** — show an "AFFECTED ASSETS:" heading once for each vulnerability:

```
{$declare[AffectedAssetsHeading][true]}
{#vulnerabilities}
{#affected_assets}
{#$equals[AffectedAssetsHeading][true]}
AFFECTED ASSETS:
{$assign[AffectedAssetsHeading][false]}
{/}
{asset}
{/}
{$assign[AffectedAssetsHeading][true]}
{/}
```

### $equalsRegExp

Checks a variable against a regular expression. The test is global and case-insensitive.

```
{$equalsRegExp[variable][/someRegExp/]}
```

| Parameter    | Description                                                                     |
| ------------ | ------------------------------------------------------------------------------- |
| **variable** | The variable's name. See `$declare`.                                            |
| **value**    | The value to compare against. Must be a regular expression, written as `/.../`. |

**Example 1:**

```
{$declare[MyName][“Bobby Brown”]}
{#$equalsRegExp[MyName][/brown/]}
My Name has Brown
{/}{^$equalsRegExp[MyName][/brown/]}
My Name does not have Brown
{/}
```

**Example 2:**

```
{$declare[TestURL][“https://google.com”]}
{#$equalsRegExp[TestURL][/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]|www\.[a-zA-Z0-9]+\.[^\s])/]}
Is a URL
{/}{^$equalsRegExp[TestURL][/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]|www\.[a-zA-Z0-9]+\.[^\s])/]}
Is NOT a URL
{/}
```

**Example 3:**

```
{$declare[TestIP][“192.168.0.1”]}
{#$equalsRegExp[TestIP][/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/]}
Is an IP address
{/}{^$equalsRegExp[TestIP][/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/]}
Is NOT an IP address
{/}
```

### $lessThan, $lessThanOrEqual, $greaterThan and $greaterThanOrEqual

Compare a number or date against a value.

```
{$lessThan[variable][value]}
{$lessThanOrEqual[variable][value]}
{$greaterThan[variable][value]}
{$greaterThanOrEqual[variable][value]}
```

| Parameter    | Description                                                                                                                     |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| **variable** | The variable's name. See `$declare`.                                                                                            |
| **value**    | The value to compare against. Supports integers, UTC datetime strings, variables that are integers, and scope in number format. |

Each example counts the affected assets for each vulnerability, prints a message if the count meets the condition, then resets the count.

**$lessThan example:**

```
{$declare[TotalAffectedAssets][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[TotalAffectedAssets][1]}
{/}
{#$lessThan[TotalAffectedAssets][5]}
There is less than 5 affected assets for this vulnerability.
{/}
{$assign[TotalAffectedAssets][0]}
{/}
```

**$lessThanOrEqual example:**

```
{$declare[TotalAffectedAssets][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[TotalAffectedAssets][1]}
{/}
{#$lessThanOrEqual[TotalAffectedAssets][5]}
There is 5 or less affected assets for this vulnerability.
{/}
{$assign[TotalAffectedAssets][0]}
{/}
```

**$greaterThan example:**

```
{$declare[TotalAffectedAssets][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[TotalAffectedAssets][1]}
{/}
{#$greaterThan[TotalAffectedAssets][5]}
There are more than 5 affected assets for this vulnerability.
{/}
{$assign[TotalAffectedAssets][0]}
{/}
```

**$greaterThanOrEqual example:**

```
{$declare[TotalAffectedAssets][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[TotalAffectedAssets][1]}
{/}
{#$greaterThanOrEqual[TotalAffectedAssets][5]}
There are 5 or more affected assets for this vulnerability.
{/}
{$assign[TotalAffectedAssets][0]}
{/}
```

### $dateDiff

Gets the difference between two dates, in milliseconds, seconds, minutes, hours, days, weeks, months or years.

```
{$dateDiff[variable/scope][value]}
```

| Parameter          | Description                                                                                        |
| ------------------ | -------------------------------------------------------------------------------------------------- |
| **variable/scope** | A variable's name (see `$declare`), or scope from the JSON file.                                   |
| **value**          | The value to compare against. Supports UTC datetime strings, variables and scope in number format. |

**Example** — store the difference between a timestamp and a fixed date in each unit:

```
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"] | declare:"diffInMilliseconds"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["milliseconds"] | declare:"diffInMilliseconds"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["seconds"] | declare:"diffInSeconds"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["minutes"] | declare:"diffInMinutes"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["hours"] | declare:"diffInHours"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["days"] | declare:"diffInDays"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["weeks"] | declare:"diffInWeeks"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["months"] | declare:"diffInMonths"}
{$dateDiff[%(timestamp)]["2026-02-27T04:28:47.515Z"]["years"] | declare:"diffInYears"}
```

## Loop and range functions

### $index

Prints the current loop index.

```
{#vulnerabilities}
{$index} - {title}
{/}
```

### $isFirst

Checks whether a loop is on its first item.

```
{#vulnerabilities}
{#$isFirst}VULNERABILITIES
{/}{title}
{/}
```

Check for every item except the first:

```
{#vulnerabilities}
{^$isFirst}NOT FIRST{/}{title}
{/}
```

### $isLast

Checks whether a loop is on its last item. This example adds a line break after every item except the last:

```
{#vulnerabilities}
{title}{^$isLast}
{/}{/}
```

Check for the last item:

```
{#vulnerabilities}
{#$isLast}IS LAST{/}{title}
{/}
```

### $range

Makes a range of numbers you can loop over.

```
{#$range[start][stop][step]}
{this}
{/}
```

| Parameter | Description                                           |
| --------- | ----------------------------------------------------- |
| **start** | A positive or negative integer, a variable, or scope. |
| **stop**  | A positive or negative integer, a variable, or scope. |
| **step**  | A positive or negative integer, a variable, or scope. |

**Example 1:**

```
{!! Range 0 -> 10 - step 1 }
{#$range[0][10][1]}
{this}
{/}
{!! Will loop 10 times, where 'this' equals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
```

**Example 2:**

```
{!! Range 10 -> 0 - step -1 }
{#$range[10][0][-1]}
{this}
{/}
{!! Will loop 10 times, where 'this' equals 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }
```

**Example 3:**

```
{$declare[Start][10]}
{$declare[Stop][00]}
{$declare[Step][-1]}
{!! Range 10 -> 0 - step -1 }
{#$range["$(Start)"]["$(Stop)"]["$(Step)"]}
{this}
{/}
{!! Will loop 10 times, where 'this' equals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
```

### $dateRange

Makes a range of dates you can loop over.

```
{#$dateRange[start][stop][step]}
{this}
{/}
```

| Parameter | Description                                                                                                                          |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| **start** | An ISO 8601 date string, a string literal, a variable, or scope.                                                                     |
| **stop**  | An ISO 8601 date string, a string literal, a variable, or scope.                                                                     |
| **step**  | A duration in milliseconds, seconds, minutes, hours, days, weeks, months or years. Can be negative. Can also be a variable or scope. |

**Example 1:**

```
{!! Range 1st Jan 2026 -> midnight 2nd Jan 2026 - step 1 day }
{#$dateRange[2026-01-01T00:00:00.000Z][2026-01-03T00:00:00.000Z][1 day]}
{this}
{/}
{!! Will loop 2 times, where 'this' equals 2026-01-01T00:00:00.000Z, 2026-01-02T00:00:00.000Z }
```

**Example 2:**

```
{!! Range 1st Jan 2026 -> 3rd Jan 2026 - step 1 day }
{#$dateRange[2026-01-01T00:00:00.000Z][2026-01-03T00:00:00.001Z][1 day]}
{this}
{/}
{!! Will loop 3 times, where 'this' equals 2026-01-01T00:00:00.000Z, 2026-01-02T00:00:00.000Z, 2026-01-03T00:00:00.000Z }
```

**Example 3:**

```
{$declare[Start]["2026-01-01T00:00:00.000Z"]}
{$declare[Stop]["2026-01-03T00:00:00.000Z"]}
{$declare[Step]["1 day"]}
{!! Range 1st Jan 2026 -> midnight 2nd Jan 2026 - step 1 day }
{#$dateRange["$(Start)"]["$(Stop)"]["$(Step)"]}
{this}
{/}
{!! Will loop 2 times, where 'this' equals 2026-01-01T00:00:00.000Z, 2026-01-02T00:00:00.000Z }
```

**Example 4** — show the date of each day between the testing start and end dates:

```
{$declare[StartDate]["%(data.testing_summary.start_date_isodatetime)"]}
{$declare[EndDate]["%(data.testing_summary.end_date_isodatetime)"]}
Start Date: {$value[StartDate]}
End Date: {$value[EndDate]}
{$declare[DayCounter][1]}
{#$dateRange["$(StartDate)"]["$(EndDate)"][1 day]}
Day {$value[DayCounter]}: {this}{$increment[DayCounter][1]}
{/}
```

## Output and debugging functions

### @$hyperlink

Creates a hyperlink.

```
{@$hyperlink[text][link]}
```

| Parameter | Description                                              |
| --------- | -------------------------------------------------------- |
| **text**  | The text to show. Supports strings, variables and scope. |
| **link**  | The URL. Supports strings, variables and scope.          |

**Example 1 — scope:**

```
{@$hyperlink[“%(projectName)”][“%(data.project.url)”]}
```

**Example 2 — manual:**

```
{@$hyperlink[“AttackForge.com”][“https://attackforge.com”]}
```

**Example 3 — variables:**

```
{$declare[Text][“Link to ReportGen”]}
{$declare[Link][“https://www.attackforge.com/reportgen.html”]}
{@$hyperlink[“$(Text)”][“$(Link)”]}
```

### $comment

Adds a comment to your template that won't appear in the report. There are two ways to write one:

```
{$comment[THIS IS A COMMENT]}
{!!THIS IS A COMMENT}
```

### $help

Prints diagnostic information to your ReportGen browser console.

```
{$help[label][function]}
```

| Parameter    | Description                                                                 |
| ------------ | --------------------------------------------------------------------------- |
| **label**    | Any label, to tell the output apart when you use several `$help` functions. |
| **function** | `var` for variables, or `scope` for scope.                                  |

**Example 1 — printing help for scope:**

```
{$help[All Report Data][scope]}
```

```
{#vulnerabilities}
{$help[Vulnerability][scope]}
{/}
```

<figure><img src="https://372186556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8s1QY2Q6YTHB4a6DMu%2Fuploads%2F0mT0PRjRmOp1snPsUes2%2FScreenshot%202026-11-10%20at%205.06.27%E2%80%AFpm.png?alt=media&amp;token=a416f26c-82e8-46a9-a33a-e7d69610cd59" alt=""><figcaption></figcaption></figure>

**Example 2 — printing help for variables:**

```
{$declare[TotalUniqueVulnerabilities][0]}
{#vulnerabilities}
{$increment[TotalUniqueVulnerabilities][1]}
{/}
{$help[My Variables][var]}
```

<figure><img src="https://372186556-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8s1QY2Q6YTHB4a6DMu%2Fuploads%2FFzYvViKBSdj4gTkHyB2X%2FScreenshot%202026-11-10%20at%205.07.40%E2%80%AFpm.png?alt=media&amp;token=35b73208-b297-4e3f-b220-10f811f6530e" alt=""><figcaption></figcaption></figure>

## Combine filters with functions

You can use filters inside a function's arguments, or chain a filter to a function's output.

**Example 1 — using a filter inside the function.** Applies `replace` filters to values inside `$value` and `$declare`:

```
{#vulnerabilities}
{#affected_assets}
{#assetCustomFields}
{$value[“%(af_sys_affected_endpoint) | replace:[“http”,”https”]”]}
{$declare[Custom][“%(af_sys_affected_endpoint) | replace:[“http”,”https”]”]}
{/}{/}{/}

{$value[“$(Custom) | replace:[“com”,”moc”]”]}
```

**Example 2 — chaining a filter to a function's output.** Pushes affected assets into a list, then filters the `$value` output:

```
{$declare[EasilyExploitableAffectedAssets][[]]}
{#vulnerabilities}
{#affected_assets}
{$push[EasilyExploitableAffectedAssets][“%(./)”]}
{/}{/}
{#$value[EasilyExploitableAffectedAssets] | filter:’easily_exploitable’}
{asset}
{/}
```

## Tips

* **Use `$help` first.** Print the scope before you write logic, so you know exactly what data you have.
* **Declare variables before loops**, and reset counters with `$assign` at the end of each loop.
* **Use `$includes` with `$push`** to build lists without duplicates.
* **Use `{#$...}` and `{^$...}` together** for if-and-else logic.
* **Use straight quotes (") in Word.** Turn off Word's smart quotes when writing tags, so quotes aren't changed to curly quotes.
* **Comment your templates** with `$comment` or `{!! ...}`, so others can follow your logic.

## FAQ

**How do I see what data I can use?** Use `$help` with `scope`. It prints the data to your ReportGen browser console.

**How do I refer to a variable inside another function?** Use `"$(variable)"`.

**How do I refer to project data inside a function?** Use scope: `"%(path)"`. Go up a level with `../`.

**How do I count something?** Declare a variable as 0, then use `$increment` in a loop.

**How do I make a list without duplicates?** Check with `{^$includes[...]}` before you `$push` each value.

**How do I do something only for the first or last item?** Use `$isFirst` or `$isLast`.

**Can I use filters in functions?** Yes. Use them inside a function's arguments, or chain them to its output.

**Will comments appear in the report?** No.

## Related pages

* [Reporting overview](https://support.attackforge.com/app/modules/reporting/overview)
* [Template options](https://support.attackforge.com/app/modules/reporting/template-options)
* [ReportGen on GitHub](https://github.com/AttackForge/ReportGen)
* [ReportGen issue #18: using $help](https://github.com/AttackForge/ReportGen/issues/18)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.attackforge.com/app/modules/reporting/template-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
