> 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-conditions.md).

# Template - Conditions

## Overview

Conditions show or hide parts of your report template, based on your project data. Use them to print only Critical findings, show a message when there are no notes, or build totals by status and priority.

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%2FLnncsAmXTa6vBHctXV7v%2Ftemplate-conditions-at-a-glance.svg?alt=media&amp;token=55766d0e-2fff-4971-858d-b0d0cc350eeb" alt=""><figcaption></figcaption></figure>

## How to write a condition

A condition starts with `#` and the expression, and ends with `{/}`. Everything between them appears only when the expression is true.

```
{#priority == "Critical"}
This appears only for Critical findings.
{/}
```

To show something when the expression is false or empty, start with `^` instead of `#`.

## Supported operators

The template engine supports many JavaScript features in conditions:

| Operator             | Meaning                                 | Example                                                                               |
| -------------------- | --------------------------------------- | ------------------------------------------------------------------------------------- |
| `==`                 | Equals                                  | `{#priority == "Critical"}`                                                           |
| `!==`                | Doesn't equal                           | `{#priority !== "Info"}`                                                              |
| `>`, `<`, `>=`, `<=` | Greater than, less than, or equal to    | `{#users.length>1}`                                                                   |
| `&&`                 | AND: both must be true                  | `{#cond2 && cond3}`                                                                   |
| `\|\|`               | OR: either can be true                  | `{#cond1 \|\| cond2}`                                                                 |
| `+`, `-`             | Add or subtract                         | `{full_name = first_name + last_name}`                                                |
| `a ? b : c`          | If `a`, use `b`, otherwise `c`          | `{#cond4 ? users : usersWithAdminRights}`                                             |
| `( )`                | Group expressions, to control the order | `{#(priority == "Critical" \|\| priority == "High") && easily_exploitable}` (example) |

## Why it matters

* **Reports that fit the data.** Show the right sections for each project, without editing the report by hand.
* **One template for many audiences.** Show detail for technical readers and summaries for executives, from the same template.
* **No empty sections.** Show a clear message instead of a blank heading when there's nothing to report.

## Who uses it

| Who                                  | To                                                   |
| ------------------------------------ | ---------------------------------------------------- |
| **Report template authors**          | Show, hide and count content based on project data   |
| **Consultancies and MSSPs**          | Tailor one template to many clients and report types |
| **Developers and integration teams** | Build advanced templates for automated reports       |

## Examples from the template engine

These general examples show the syntax. They don't use AttackForge data.

A section that appears only when there are two or more users, and one that appears only when `userName` equals "John":

```
{#users.length>1}
There are multiple users
{/}

{#userName == "John"}
Hello John, welcome back
{/}
```

OR, AND and a ternary expression, nested in another condition:

```
{#generalCondition}
{#cond1 || cond2}
Paragraph 1
{/}
{#cond2 && cond3}
Paragraph 2
{/}
{#cond4 ? users : usersWithAdminRights}
Paragraph 3
{/}
There are {users.length} users.
{/generalCondition}
```

## Show or hide content

### IF statements

Show content only when a condition is true. This example prints only Critical vulnerabilities:

```
{#vulnerabilities}
{#priority == "Critical"}
Critical Vulnerability: {title}
{/}{/}
```

### IF AND statements

Show content only when both conditions are true. This example prints only Critical vulnerabilities titled SQL Injection:

```
{#vulnerabilities}
{#priority == "Critical" && title == "SQL Injection"}
Critical Vulnerability: SQL Injection
{/}{/}
```

### IF OR statements

Show content when either condition is true. This example prints Critical and High vulnerabilities:

```
{#vulnerabilities}
{#priority == "Critical" || priority == "High"}
{priority} - {title}
{/}{/}
```

### IF ELSE statements

Show one thing when there's data, and something else when there isn't. This example prints each project note, or "No project notes found." if there are none:

```
{#projectNotes}
{note}
{/}
{^projectNotes}
No project notes found.
{/}
```

### Check whether something exists

`{#tag}` is true when a tag has a value. On a list, `{#list}...{/}` repeats its content once for each item, so to show something only once when a list has items, check its length:

```
{#affected_assets.length > 0}
Affected assets:
{/}
```

## Go further

### Conditional logic and counting

You can combine conditions with [filters](https://support.attackforge.com/app/modules/reporting/template-filters) and [functions](https://support.attackforge.com/app/modules/reporting/template-functions) to create powerful logic in your reports.

This example counts affected assets by remediation status, leaving out Info findings, then prints the totals.

```
{$declare[TotalVulnerabilities][0]}
{$declare[TotalFixedVulnsExInfo][0]}
{$declare[TotalRetestVulnsExInfo][0]}
{$declare[TotalNotFixedVulnsExInfo][0]}
{#vulnerabilities}
{#affected_assets}
{$increment[TotalVulnerabilities][1]}
{#remediation_status | includes:[“Open”]}
{#priority !== “Info”}
{$increment[TotalNotFixedVulnsExInfo][1]}
{/}{/}
{#remediation_status | includes:[“Ready for Retest”]}
{#priority !== “Info”}
{$increment[TotalRetestVulnsExInfo][1]}{/}{/}
{#remediation_status | includes:[“Closed”]}
{#priority !== “Info”}
{$increment[TotalFixedVulnsExInfo][1]}{/}{/}
{/affected_assets}
{/vulnerabilities}

Total Vulnerabilities for All Affected Assets:
{$value[TotalVulnerabilities]}

Total Open/Not Fixed Vulnerabilities which are Not Informational:
{$value[TotalNotFixedVulnsExInfo]}

Total Retest Vulnerabilities for All Affected Assets:
{$value[TotalRetestVulnsExInfo]}

Total Fixed Vulnerabilities for All Affected Assets:
{$value[TotalFixedVulnsExInfo]}
```

### Data formatting

Show numbers with two decimal places, such as 150.00, with `toFloat:'2'`.

Sample data:

```json
{
    "items": [
        {
            "name": "Acme Computer",
            "price": 1000,
        },
        {
            "name": "Mouse & Keyboard",
            "price": 150,
        }
    ],
}
```

Template:

```
{#items}
{name} for a price of {price | toFloat:'2'} €
{/}
```

### Assignments

You can assign a value to a variable directly in your template:

```
{full_name = first_name + last_name}
```

The problem is that this expression also prints the value of `full_name`. To stop that, add a second statement that returns an empty string:

```
{full_name = first_name + last_name; ''}
```

This runs the assignment first, then the empty string, and prints only the empty string.

For most templates, the [`$declare` and `$assign` functions](https://support.attackforge.com/app/modules/reporting/template-functions) are an easier way to work with variables.

## Quick reference

| To                     | Write                                              |
| ---------------------- | -------------------------------------------------- |
| Show if true           | `{#condition}...{/}`                               |
| Show if false or empty | `{^condition}...{/}`                               |
| If, otherwise          | `{#tag}...{/}{^tag}...{/}`                         |
| AND                    | `{#a && b}...{/}`                                  |
| OR                     | `{#a \|\| b}...{/}`                                |
| Not equal              | `{#priority !== "Info"}...{/}`                     |
| Combine with a filter  | `{#remediation_status \| includes:["Open"]}...{/}` |

## Tips

* **Close every condition.** Each `{#...}` or `{^...}` needs its own `{/}`. Count them when nesting.
* **Pair `{#...}` with `{^...}`** to show a clear message instead of an empty section.
* **Use filters inside conditions,** such as `includes`, to match part of a value.
* **Use functions to count,** then print the totals with `$value`.
* **Check your data with `$help`** to see the exact values, such as how a priority or status is spelt.
* **Values are case-sensitive.** `"Critical"` and `"critical"` don't match.
* **Use straight quotes (") in Word.** Turn off Word's smart quotes when writing conditions.

## FAQ

**How do I write "else"?** Close the `{#...}` condition, then add a `{^...}` condition with the same expression or tag.

**Can I combine AND and OR?** Yes. Use brackets to control the order, such as `{#(a || b) && c}`.

**How do I check that something isn't equal?** Use `!==`, such as `{#priority !== "Info"}`.

**Why does my text repeat?** `{#list}` loops over each item. To show text once, put it outside the loop, or check the list's length.

**Can I use conditions in tables?** Yes. See [Template Tables](https://support.attackforge.com/app/modules/reporting/template-tables).

**What's the difference between conditions and the `filter` filter?** Conditions show or hide a section. `filter` keeps only the list items that match, so you loop over fewer items. See [Template Filters](https://support.attackforge.com/app/modules/reporting/template-filters).

## Related pages

* [Reporting overview](https://support.attackforge.com/app/modules/reporting/overview)
* [Template functions](https://support.attackforge.com/app/modules/reporting/template-functions)
* [Template filters](https://support.attackforge.com/app/modules/reporting/template-filters)
* [Template tables](https://support.attackforge.com/app/modules/reporting/template-tables)
* [Template options](https://support.attackforge.com/app/modules/reporting/template-options)
* [ReportGen on GitHub](https://github.com/AttackForge/ReportGen)


---

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