# Conditional Logic In Microsoft Templates (DOCX, PPTX, XLSX)

Use this page when your `RENDER` statement works in the HTML editor but needs DOCX syntax.

The logic stays the same.

The wrapping syntax changes.

### Core rules

1. Wrap opening and closing `RENDER` tags in square brackets.
2. Keep the logical expression inside the `RENDER` tag.
3. Wrap merge fields in DOCX content with square brackets.

### Basic pattern

{% code title="docx-render-basic.txt" %}

```plaintext
[<!--RENDER='{{!Opportunity.StageName}}' == 'Closed Won' -->]
  This opportunity is closed won.
[<!--ENDRENDER-->]
```

{% endcode %}

### Show conditional content with a merge field

Use square brackets for the merge field inside the rendered content.

{% code title="docx-render-with-merge-field.txt" %}

```plaintext
[<!--RENDER='{{!Contact.Phone}}' != 'NULL' -->]
  Phone number: [{{!Contact.Phone}}]
[<!--ENDRENDER-->]
```

{% endcode %}

### Use `AND` and `OR`

`&&`, `||`, and parentheses work in DOCX too.

{% code title="docx-render-and-or.txt" %}

```plaintext
[<!--RENDER=( ('{{!Account.BillingState}}' == 'CA' || '{{!Account.BillingState}}' == 'NV')
             && '{{!Account.Active_Contract__c}}' == 'True' ) -->]
  Customer is in CA or NV and has an active contract.
[<!--ENDRENDER-->]
```

{% endcode %}

### Use nested render blocks

Nested render blocks follow the same naming rules as standard templates.

{% code title="docx-render-nested.txt" %}

```plaintext
[<!--RENDER='{{!Opportunity.StageName}}' == 'Closed Won' -->]
  Congratulations on your purchase.
  [<!--RENDER1='{{!Opportunity.Install_Date__c}}' != 'NULL' -->]
    Installation is scheduled for [{{!Opportunity.Install_Date__c}}].
  [<!--ENDRENDER1-->]
[<!--ENDRENDER-->]
```

{% endcode %}

{% hint style="info" %}
Use the same operators you use in standard conditional logic.

That includes `==`, `!=`, `>`, `<`, `>=`, `<=`, `CONTAINS`, `NOT CONTAINS`, `&&`, and `||`.
{% endhint %}

### Common fixes

* **Blank output:** Make sure both the opening tag and the closing tag use square brackets.
* **Field prints as text:** Use `[{{!FieldName}}]` in DOCX content.
* **Nested logic fails:** Match `RENDER1` with `ENDRENDER1`, `RENDER2` with `ENDRENDER2`, and so on.
* **Expression is hard to debug:** Test the logic in a standard template first. Then convert the outer wrapping for DOCX.

### Keep going

* Review [Conditional Logic Structure](/developer-hub/template-configuration-and-styling/conditional-logic-reference/conditional-logic-structure.md) for base syntax and supported operators
* Review [Conditional Logic Working Examples](/developer-hub/template-configuration-and-styling/conditional-logic-reference/conditional-logic-working-examples.md) for reusable patterns
* Review [Named Queries in DOCX and PPTX](/developer-hub/template-configuration-and-styling/reference-named-query-syntax/named-queries-in-microsoft-templates-docx-pptx-xlsx.md) if your DOCX template also uses query-based data blocks


---

# 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/developer-hub/template-configuration-and-styling/conditional-logic-reference/conditional-logic-in-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.
