# How to Show or Hide Content Automatically

Use this tutorial when one template must generate different output for different records.

## What it looks like

After setup, one quote can produce all of this:

* A VIP message only for high-value customers
* A phone line only when `Contact.Phone` has a value
* A California clause only for active contracts
* A finance compliance note only for matching industries
* Reusable rule patterns for other templates

This works well for quotes, contracts, and renewal documents.

## When to use conditional logic

Use conditional logic when content should appear only when record data passes a rule.

**Best for:**

* Hiding empty labels and optional sections
* Showing regional or industry-specific clauses
* Reusing one template across several customer scenarios

Use another feature when the job is different:

* Use [Template Attributes Tutorial](/quick-start/template-building/how-to-format-text-dates-and-currency.md) when you need formatting only.
* Use [Get Started with Calculations](/quick-start/template-building/get-started-with-calculations.md) when you need thresholds or derived values.
* Use [Creating Your First Named Query](/quick-start/template-building/creating-your-first-named-query-tutorial.md) when you need reusable query output.

## Build a quote template with conditional logic

### What you'll configure

* A basic `RENDER` block
* Empty-field checks with `!= 'NULL'`
* Multi-part rules with `&&` and `||`
* Keyword matching with `CONTAINS`
* A quick test plan for validating output

**Estimated time:** 20 minutes

### Prerequisites

Before you start, make sure you have:

* Access to **S-Docs Templates**
* Permission to create or edit templates
* An S-Docs template related to `Account`, `Contact`, or `Opportunity`
* Test records with known field values
* Basic familiarity with merge fields such as `{{!Account.Name}}`

If you are brand new to S-Docs syntax, start with a merge field tutorial first.

{% stepper %}
{% step %}

### Step 1: Open or create the template

Start with a template that should change by record data.

1. Go to **S-Docs Templates** in Salesforce.
2. Open an existing template or click **New Template**.
3. Set the correct base object.
4. Open the template editor.
5. Click **Source** if you want to paste syntax directly.

You now have a place to add conditional blocks.
{% endstep %}

{% step %}

### Step 2: Add a simple equality check

Start with one short block. This confirms the syntax works before you add more logic.

Add this where the VIP note should appear:

{% code title="vip-message.html" %}

```html
<!--RENDER='{{!Account.Customer_Type__c}}' == 'High Value' -->
<p><strong>VIP customer:</strong> Thank you for your continued business.</p>
<!--ENDRENDER-->
```

{% endcode %}

What you just did:

* Compared `Account.Customer_Type__c` to one exact text value
* Used `==` for an equality check
* Rendered the paragraph only when the condition passes

How to read the syntax:

* `{{!Account.Customer_Type__c}}` is the field being checked
* `==` means the value must match exactly
* `'High Value'` is the required text
  {% endstep %}

{% step %}

### Step 3: Hide a blank phone line

Use a null check when the label and value should appear together.

Add this block in the contact section:

{% code title="phone-line.html" %}

```html
<!--RENDER='{{!Contact.Phone}}' != 'NULL' -->
<p>Phone: {{!Contact.Phone}}</p>
<!--ENDRENDER-->
```

{% endcode %}

What you just did:

* Used `!=` for a not-equal check
* Compared the field to `NULL`
* Prevented an empty `Phone:` label from printing

This pattern works well for phone, email, title, and address lines.
{% endstep %}

{% step %}

### Step 4: Require two conditions with AND

Use AND logic when both checks must pass before showing content.

Add this clause below the customer summary:

{% code title="regional-clause.html" %}

```html
<!--RENDER=( '{{!Account.BillingState}}' == 'CA' && '{{!Account.Active_Contract__c}}' == 'True' ) -->
<p>Include the California active-contract clause in this quote.</p>
<!--ENDRENDER-->
```

{% endcode %}

What you just did:

* Used `&&` for AND logic
* Grouped both checks with parentheses
* Rendered the clause only when both values match

Read the condition in order:

* `BillingState` must equal `CA`
* `Active_Contract__c` must equal `True`
* `&&` means both statements must be true
  {% endstep %}

{% step %}

### Step 5: Match either value with OR

Use OR logic when one of several values should show the same content.

Add this example:

{% code title="west-coast-note.html" %}

```html
<!--RENDER=( '{{!Account.BillingState}}' == 'CA' || '{{!Account.BillingState}}' == 'OR' ) -->
<p>Apply the West Coast delivery language.</p>
<!--ENDRENDER-->
```

{% endcode %}

What you just did:

* Used `||` for OR logic
* Allowed either state to trigger the note
* Reused the same field in two checks

Use this pattern for state groups, segment groups, or status groups.
{% endstep %}

{% step %}

### Step 6: Match a keyword with CONTAINS

Use `CONTAINS` when the source text can vary.

Add this block in the compliance section:

{% code title="industry-keyword.html" %}

```html
<!--RENDER='{{!Account.Industry}}' CONTAINS 'Finance' -->
<p>Include the finance compliance checklist with this document.</p>
<!--ENDRENDER-->
```

{% endcode %}

What you just did:

* Searched within the full field value
* Matched text like `Finance Team` or `Global Finance`
* Avoided relying on one exact field value

If you need the inverse, use `NOT CONTAINS`.
{% endstep %}

{% step %}

### Step 7: Save and test the output

Test one rule at a time before combining more patterns.

1. Click **Save** in the template editor.
2. Generate the template from a record that should pass one rule.
3. Generate it again from a record that should fail.
4. Compare the output blocks.

Verify these results:

* The VIP note shows only for high-value customers
* The phone line shows only when `Contact.Phone` is populated
* The California clause shows only when both checks pass
* The finance note shows only when the keyword exists
  {% endstep %}
  {% endstepper %}

### Try these variations

Use these once the base version works.

An amount threshold:

{% code title="amount-threshold.html" %}

```html
<!--RENDER={{!Opportunity.Amount}} > 10000 -->
<p><strong>Manager review required.</strong></p>
<!--ENDRENDER-->
```

{% endcode %}

A negative keyword match:

{% code title="negative-keyword.html" %}

```html
<!--RENDER='{{!Case.Subject}}' NOT CONTAINS 'Urgent' -->
<p>Route this case through the standard workflow.</p>
<!--ENDRENDER-->
```

{% endcode %}

A combined customer and industry check:

{% code title="combined-condition.html" %}

```html
<!--RENDER=( '{{!Account.Type}}' == 'Customer' && '{{!Account.Industry}}' CONTAINS 'Finance' ) -->
<p>Apply the customer finance compliance clause.</p>
<!--ENDRENDER-->
```

{% endcode %}

## Guardrails and limits

### Syntax rules

* **Always** close each block with `<!--ENDRENDER-->`.
* **Always** keep the full label and value inside the same block.
* **Always** use exact field API names.
* If you miss the closing tag, later content can disappear.

### Operator rules

* **Use** `==` for exact matches.
* **Use** `!= 'NULL'` for blank-value checks.
* **Wrap** multi-part conditions in parentheses.
* If the operator is wrong, the block stays hidden.

### Text-matching rules

* **Match** text values exactly when you use `==`.
* **Use** `CONTAINS` when field values vary.
* **Check** capitalization and spacing in test data.
* If the value differs, S-Docs skips the block.

### Testing rules

* **Generate** one document after each major syntax change.
* **Test** one condition alone before combining conditions.
* **Use** records that clearly pass and fail each rule.
* If you skip this, debugging gets much slower.


---

# 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/quick-start/template-building/conditional-logic-tutorial.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.
