> For the complete documentation index, see [llms.txt](https://docs.agilecase.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agilecase.com/administrator-documentation/templates/creating-a-document-template-with-an-if-block.md).

# Creating a Document Template with an IF block

This lesson will show you how to create more complex document templates using IF blocks. Before you try this, you should know how to create a simple template, which you can find [here](/administrator-documentation/templates/creating-a-simple-document-template.md).

## Creating an IF block

<figure><img src="/files/yuufsAwTPS6ic30foDBB" alt=""><figcaption></figcaption></figure>

A more complex kind of mergefield is an IF block.

This allows you to create if statements that will generate different outcomes depending on whether or not the IF condition is satisfied.

For example, the IF block in this field is:

```
{IF {MERGEFIELD Contact.PrimaryClient.Name} <> "" "and our primary contact in your organization {MERGEFIELD Contact.PrimaryClient.Name}"}
```

This means that if the primary client name is not equal (`<>`) to blank (`""`), then the result `and our primary contact in your organization {MERGEFIELD Contact.PrimaryClient.Name}` will be generated in the document.

In this case, the IF block is allowing you to add additional contextual text to take into account the existence of a primary client.

{% stepper %}
{% step %}

## Activate mail merge mode

Press `alt+F9` to activate mail merge mode.
{% endstep %}

{% step %}

## Create a field

Press `ctrl+F9` to create a field.
{% endstep %}

{% step %}

## Enter the IF condition

Enter `IF`, then enter your condition. In this case:

```
{MERGEFIELD Contact.PrimaryClient.Name} <> ""
```

{% endstep %}

{% step %}

## Enter the result

Enter the result inside quotation marks.

Following this format, you can create increasingly complex IF statements that will react to different case information in a contextual manner.
{% endstep %}
{% endstepper %}

The following examples show the result of an IF block when the condition is, and is not, satisfied.

## Outcome when condition is satisfied

<figure><img src="/files/7SvwwsXMPsnp0nhgVDXA" alt=""><figcaption></figcaption></figure>

This example has been generated when the case has a primary client. You can see the text prescribed in the IF block is also generated as the condition has been satisfied.

## Outcome when condition is not satisfied

<figure><img src="/files/BzcvAlB3J1IBopgChPGV" alt=""><figcaption></figcaption></figure>

In this example, the primary client has been removed so the IF condition is not satisfied. As a result, the prescribed text is not generated either, completely removing any mention of the primary client.


---

# 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.agilecase.com/administrator-documentation/templates/creating-a-document-template-with-an-if-block.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.
