# Quick Setup: Conditional Logic With Microsoft Templates (DOCX, PPTX, XLSX)

## Quick setup for conditional logic in DOCX templates

Conditional logic works in DOCX templates.

The logic stays the same.

The wrapper changes.

In DOCX, wrap each `RENDER` tag in square brackets.

Use DOCX merge fields inside the content you want to output.

### Basic pattern

```plaintext
[<!--RENDER=logical_expression -->]
  content to show if expression is true
[<!--ENDRENDER-->]
```

### Basic example

Use this pattern when the condition checks one field and the output shows another.

```plaintext
[<!--RENDER='{{!Opportunity.StageName}}' == 'Closed Won' -->]
  Closed amount: [{{!Opportunity.Amount #,###.##}}]
[<!--ENDRENDER-->]
```

The field inside the condition stays in standard merge syntax.

The visible output field uses DOCX merge syntax.

{% hint style="info" %}
Use square brackets around the opening and closing `RENDER` tags.

Use square brackets around any merge field that should print in the DOCX output.
{% endhint %}

### AND and OR logic

Use parentheses around combined conditions.

#### AND

```plaintext
[<!--RENDER=('{{!Opportunity.StageName}}' == 'Closed Won' && '{{!Opportunity.Amount}}' != '0') -->]
  Closed amount: [{{!Opportunity.Amount #,###.##}}]
[<!--ENDRENDER-->]
```

#### OR

```plaintext
[<!--RENDER=('{{!Opportunity.StageName}}' == 'Closed Won' || '{{!Opportunity.StageName}}' == 'Contract Signed') -->]
  Status: [{{!Opportunity.StageName}}]
[<!--ENDRENDER-->]
```

### Nested conditional logic

You can nest up to 4 levels deep.

Use a distinct tag for each nested level.

Do not skip levels.

#### Two levels

```plaintext
[<!--RENDER='{{!Contact.Phone}}' == 'NULL' -->]
  [<!--RENDER1='{{!Contact.MobilePhone}}' == 'NULL' -->]
    No phone numbers are available.
  [<!--ENDRENDER1-->]
[<!--ENDRENDER-->]
```

#### Three levels

```plaintext
[<!--RENDER='{{!Opportunity.StageName}}' == 'Closed Won' -->]
  [<!--RENDER1='{{!Opportunity.Amount}}' != '0' -->]
    Amount: [{{!Opportunity.Amount #,###.##}}]
    [<!--RENDER2='{{!Opportunity.Type}}' == 'New Customer' -->]
      New customer sale.
    [<!--ENDRENDER2-->]
  [<!--ENDRENDER1-->]
[<!--ENDRENDER-->]
```

### CONTAINS and NOT CONTAINS

Use `CONTAINS` when you need a partial text match.

```plaintext
[<!--RENDER='{{!Contact.Name}}' CONTAINS 'Steve' -->]
  Name contains Steve.
[<!--ENDRENDER-->]
```

Use `NOT CONTAINS` for the inverse.

```plaintext
[<!--RENDER='{{!Contact.Name}}' NOT CONTAINS 'Steve' -->]
  Name does not contain Steve.
[<!--ENDRENDER-->]
```

### When to use template logic

#### Best for

* Showing or hiding sections based on field values
* Reusing one DOCX template across multiple scenarios
* Keeping document rules inside the template

#### Less ideal for

* Very large content blocks controlled by simple rules
* Logic that already exists in formula fields or automation

{% hint style="warning" %}
Test null values and edge cases.

Keep every opening tag paired with the matching closing tag.

Keep HTML or Word content fully inside or fully outside a `RENDER` block.

If a visible field prints in the output, wrap that field in square brackets.
{% endhint %}

### Related articles

* [Merge Fields With Microsoft Templates (DOCX, PPTX, XLSX)](/sdocs/template-architecture/inserting-merge-fields/merge-fields-with-microsoft-templates-docx-pptx-xlsx.md)
* [Handle Escaped Characters in RENDER Statements](/sdocs/advanced-template-logic/conditional-logic/handle-escaped-characters-in-render-statements.md)
* [Microsoft Word (DOCX)](/sdocs/template-architecture/document-formats/docx-s-docs.md)


---

# 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://help.sdocs.com/sdocs/advanced-template-logic/conditional-logic/quick-setup-conditional-logic-with-microsoft-templates-docx-pptx-xlsx.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.
