# Conditions

Conditions enable you to control the display of parts of your template based on conditional data:

* either a boolean (true/ false)
* or the presence of the data itself

{% hint style="info" %}
We recommend that when using conditions, you should always use tags starting with if\_, like  {#if\_myTag} text to be dislayed if true {/if\_myTag}. This will enable docMaker to know that you are using this tag as a conditional tag.
{% endhint %}

A condition section begins with a pound and ends with a slash. That is {#if\_person} begins a "if\_person" section while {/if\_person} ends it.

> **Example :** if you use in your template : {#if\_myTag} conditional data {/if\_myTag} => if you send {"if\_myTag" = true} the data inside  the{#if\_myTag} section will be displayed.

You may also use inverted sections to display data when the condition is false :&#x20;

> **Example :**  in your template : {^if\_myTag} conditional data {/if\_myTag} => if you send {"if\_myTag" = false} the data inside  the {^if\_myTag} section will be displayed.

Check out the examples below.&#x20;

### Example 1: block not displayed <a href="#example-1-block-not-displayed" id="example-1-block-not-displayed"></a>

Data

{% code lineNumbers="true" %}

```json
{
  "if_display" : false,
  "firstname": "John",
  "lastname": "Doe"
}
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="280.3333333333333"></th><th align="center"></th><th></th></tr></thead><tbody><tr><td><strong>Template</strong></td><td align="center"> </td><td><strong>Result</strong></td></tr><tr><td><p>{#if_display}</p><p>Hello {firstname} !                       </p><p>{/if_display}          </p><p>Your last name is {lastname} !                            </p></td><td align="center"><p><span data-gb-custom-inline data-tag="emoji" data-code="27a1">➡️</span></p><p> </p></td><td>Your last name is Doe!                              </td></tr></tbody></table>

&#x20;

### Example 2: block displayed <a href="#example-2-block-displayed" id="example-2-block-displayed"></a>

**Data**

{% code lineNumbers="true" %}

```json
{
  "if_display" : true,
  "firstname": "John",
  "lastname": "Doe"
}
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="349.3333333333333"></th><th width="88" align="center"></th><th></th></tr></thead><tbody><tr><td><strong>Template</strong></td><td align="center"> </td><td><strong>Result</strong></td></tr><tr><td><p>{#if_display}</p><p>Hello {firstname} !                       </p><p>{/if_display}          </p><p>Your last name is {lastname} !                            </p></td><td align="center"><p><span data-gb-custom-inline data-tag="emoji" data-code="27a1">➡️</span></p><p> </p></td><td><p>Hello John!</p><p>Your last name is Doe!                              </p></td></tr></tbody></table>

&#x20;

### Example 3: block not displayed based on data itself <a href="#example-3-block-not-displayed-based-on-data-itself" id="example-3-block-not-displayed-based-on-data-itself"></a>

**Data**

{% code lineNumbers="true" %}

```json
{
  "firstname": null,
  "lastname": "Doe"
}
```

{% endcode %}

<table data-header-hidden><thead><tr><th></th><th width="130.33333333333331" align="center"></th><th></th></tr></thead><tbody><tr><td><strong>Template</strong></td><td align="center"> </td><td><strong>Result</strong></td></tr><tr><td><p>{#firstname}</p><p>Hello {firstname} !                       </p><p>{/firstname}          </p><p>Your last name is {lastname} !                            </p></td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="27a1">➡️</span></td><td>Your last name is Doe!                              </td></tr></tbody></table>

### Example 4: inverted conditions <a href="#example-4-inverted-conditions" id="example-4-inverted-conditions"></a>

An inverted section begins with a caret (hat) and ends with a slash. That is {^person} begins a "person" inverted section while {/person} ends it.

**Data**

{% code lineNumbers="true" %}

```json
{
  "if_display" : false,
  "firstname": "John",
  "lastname": "Doe"
}
```

{% endcode %}

<table data-header-hidden><thead><tr><th width="312.3333333333333"></th><th width="148" align="center"></th><th></th></tr></thead><tbody><tr><td><strong>Template</strong></td><td align="center"> </td><td>Result</td></tr><tr><td><p>{#if_display}</p><p>Hello {firstname} !                       </p><p>{/if_display}          </p><p>{^if_display}</p><p>Inverted hello {firstname} !                       </p><p>{/if_display}      </p><p>Your last name is {lastname} !                            </p></td><td align="center"><p><span data-gb-custom-inline data-tag="emoji" data-code="27a1">➡️</span></p><p> </p></td><td><p>Inverted hello John!</p><p>Your last name is Doe!                              </p></td></tr></tbody></table>

&#x20;


---

# 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://guide.docmaker.co/features/create-pdf-from-docx-template/build-your-docx-template/conditions.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.
