# Quick Setup: Conditional Logic

## Using S-Docs Render Statements

This is the main way to include or exclude sections of a document based on logic *within the template itself*. It does not require creating new Salesforce fields.

### Basic structure

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

The engine evaluates `logical_expression`; if TRUE, everything up to `ENDRENDER` appears in the final document.

{% hint style="info" %}
If you are interested, please check out my [working examples article](file:///8426358/conditional-logic-render-statements/conditional-logic-working-examples.md) for quick reference!
{% endhint %}

***

### AND / OR Logic Structure

AND

```
<!--RENDER=(logical_expression-1 && logical_expression-2) -->
  content to show if expression is true
<!--ENDRENDER-->
```

OR

```
<!--RENDER=(logical_expression-1 || logical_expression-2) -->
  content to show if expression is true
<!--ENDRENDER-->
```

* The expressions need to be contained within parenthesis.
* && or || are important to use.

***

### Nested Conditional Logic

You can nest up to 4 levels deep. This lets you represent dependent conditions—for example, missing phone and alternate numbers:

```
<!--RENDER=logical_expression_1stlevel -->
  content to show if expression is true
  <!--RENDER1=logical_expression_2ndlevel -->
    content to show if expression is true
  <!--ENDRENDER1-->
<!--ENDRENDER-->
```

```
<!--RENDER=logical_expression_1stlevel -->
  content to show if expression is true
  <!--RENDER1=logical_expression_2ndlevel -->
    content to show if expression is true
    <!--RENDER2=logical_expression_3rdlevel-1 -->
      content to show if expression is true
    <!--ENDRENDER2-->
    <!--RENDER2=logical_expression_3rdlevel-2 -->
      additional content to show if expression is true
    <!--ENDRENDER2-->
  <!--ENDRENDER1-->
<!--ENDRENDER-->
```

A few requirements:\
✔ Each nested level must use a distinct render tag (RENDER1, RENDER2, etc.)\
✔ Tags must be properly paired\
✔ No skipping levels (i.e., RENDER2 must be inside RENDER1)

***

### CONTAINS & NOT CONTAINS

If you want to check if a field *contains* a substring:

```
<!--RENDER='{{!Contact.Name}}' CONTAINS 'Steve' -->
  Name contains “Tim”.
<!--ENDRENDER-->
```

And the opposite:

```
<!--RENDER='{{!Contact.Name}}' NOT CONTAINS 'Steve' -->
  Name does not contain “Tim”.
<!--ENDRENDER-->
```

This is helpful when looking for keywords or partial matches in text fields.

***

## When You Should (and Shouldn’t) Use Template Logic

### Best For

✅ Dynamic document content that varies by prefix, status, tier, field values, etc.\
✅ Avoiding dozens of separate templates\
✅ Complex visibility logic embedded in template

### Less Ideal For

❌ Extremely large text blocks controlled by simple rules — consider formula fields\
❌ Logic that already exists elsewhere in your Salesforce processes

{% hint style="warning" %}

#### Pro Tips

* Always test edge cases (e.g., null values, unexpected values).
* Use AND/OR to simplify nested structures when deep nesting isn’t necessary.
* If text needs to be replaced within text area fields or rich text fields, consider the replaceall attribute.
* If render statements are needed in fields with character limits or are quite complex, consider formula fields or callable apex to achieve the goal.
* Ensure all HTML tags are either included in or outside of RENDER statements. If there is a mismatch, the template editor will save, but the document generation will fail.
  {% endhint %}


---

# 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/conditional-logic-how-to.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.
