Show or Hide Document Sections Based on Salesforce Fields
Show vs hide — choosing the right action
When you apply a condition to an element, you choose whether the condition shows or hides the element when true. These two approaches produce the same result but suit different template design patterns — choosing the right one makes your conditions easier to read and maintain.
When in doubt, use Show when true. It follows the principle that conditional content is "off by default" and only appears when the data warrants it — making your template logic predictable and easier to audit.
Scope — what you can show or hide
Show/hide conditions can be applied at different levels of the document structure — from an entire page section down to a single inline sentence. The broader the scope, the simpler the template to maintain.
Section
An entire named section of the document — heading plus all body content. Best for large optional blocks like "Appendix A", "GDPR Terms", or "Premium Support SLA".
Paragraph
A single paragraph of body text. Use when only one clause or explanation should be conditional within a larger section that always appears.
Table
An entire table — header row and all data rows. Use when a whole data block (e.g. a pricing breakdown) should only appear for specific deal types.
Table row
A single row within a table. Use to filter individual line items — e.g. show only rows where a line item field meets a criterion. See Dynamic tables.
Image
A logo, diagram, or signature block image. Use when a visual element should only appear for certain customers — e.g. a partner logo only when Account.Type = "Partner".
Inline text
A word, phrase, or sentence within a paragraph. Use for small substitutions — e.g. showing "Exclusive" before "pricing" for VIP accounts. For longer inline branches, use if/else syntax instead.
How it looks in the document
The same template generating two different documents — one for an Enterprise account, one for a Standard account. The Enterprise-specific sections are shown on the left and absent on the right:
When a section is hidden, it is completely removed from the generated document — no blank space, no placeholder, no visible indicator that a section was conditional. The surrounding content flows together as if the section was never there.
Conditions by field type
The right condition syntax varies by Salesforce field type. Here is how to write show/hide conditions for the most common field types:
Picklist / Select
Checkbox / Boolean
Number / Currency
Text / Long Text
Date / DateTime
Empty / Null check
Step-by-step: hiding a section using a Salesforce field
This example hides the "Standard Payment Terms" paragraph when the Custom_Terms__c field on the Opportunity is populated — ensuring custom terms replace the standard terms rather than both appearing.
Click the "Standard Payment Terms" paragraph in the editor
Open your template in the editor. Click the paragraph that contains the standard payment terms text. The paragraph is selected — you can see a blue outline around it.
Open the Conditional Logic tab in the element properties
In the right-hand properties panel, click Conditional Logic. Click Add Condition. The condition builder opens with three fields: Field, Operator, Value.
Set the condition: Custom_Terms__c is not blank
- Field: Select
Custom_Terms__cfrom the field picker - Operator: Select
is not blank - Value: Leave empty — the "is not blank" operator needs no comparison value
Set the action to "Hide when condition is true"
In the Action dropdown below the condition, select Hide when condition is true. This means: when Custom_Terms__c has a value, hide the standard terms. When it's blank, show the standard terms.
Save and preview against two test records
Save the template. Preview it against a record with Custom_Terms__c populated — the standard paragraph should be absent. Preview again against a record with Custom_Terms__c blank — the standard paragraph should appear. Both outcomes verified.
Pattern library — ready-to-use show/hide conditions
Copy these patterns directly into your templates. All use Show when true unless noted.
Show GDPR data processing annex for EU customers
Field: Account.BillingCountry — Operator: contains — Value: country name (repeat with OR for each EU country, or use a formula field that categorises by region). Show when true.
Show enterprise SLA only for large deals
Field: Amount — Operator: greater than or equal — Value: 100000. Show when true. If you also want a "Growth SLA" for medium deals, add an else-if: Amount >= 25000 shows Growth SLA, else shows Standard SLA.
Show late payment fee clause only when applicable
Field: Late_Fee_Applicable__c (checkbox) — Operator: is true. Show when true. The late fee clause is completely invisible on invoices where it doesn't apply.
Show renewal-specific introduction for returning customers
Field: Is_Renewal__c (checkbox) — Operator: is true. Show when true. Add an else branch showing the new-customer introduction when Is_Renewal__c is false. One template, two openers.
Show custom pricing note only when custom pricing is in use
Field: Pricing_Override__c (text) — Operator: is not blank. Show when true. The note "This quote reflects negotiated pricing — standard rates may apply to future orders" appears only when there's a pricing override reason on record.
Hide a section for internal accounts (test/demo records)
Field: Account.Type — Operator: equals — Value: Internal. Hide when true. Prevents internal test records from generating documents with customer-facing clauses. An important safeguard for demo environments.
Handling whitespace after hidden sections
When a section is hidden, Dochly removes the element entirely — including any paragraph spacing above and below it. In most cases this produces clean results. However, if you have a section heading immediately above a conditional body paragraph, the heading may remain when the body is hidden.
The cleanest pattern: wrap both the section heading and the conditional body paragraph in a container or group element, then apply the show/hide condition to the entire group. Both heading and body disappear together — no orphaned headings.
If grouping isn't available, apply the same condition to the heading element separately — using the same field, operator, and value. Both the heading and body will hide together. Keep both conditions identical so they always toggle in sync.
The recommended pattern is always to group conditional content — heading, body text, and any sub-elements — in a single container and apply the condition to the container. This is safer than applying conditions individually to multiple sibling elements, and prevents orphaned content if you later add more content to the section.
Testing show/hide conditions
Every show/hide condition has two outcomes — the element is shown or it isn't. Both must be tested before setting a template Active.
Preview the template using a record where the condition is true — e.g. for Amount > 50,000, use a real Opportunity with a high amount. Confirm the section appears in the correct position, with correct content, and no formatting issues from the surrounding text.
Preview using a record where the condition is false — e.g. a low-value Opportunity. Confirm the section is completely absent. Check the surrounding paragraphs flow cleanly together with no extra blank lines or spacing where the section was.
Frequently asked questions
Show/hide conditions are now working in your template. Next in this series: Use if/else conditions in a Dochly document template — switch inline text, output different clauses, and build multi-branch logic within a single paragraph or sentence.
Rated 5 stars · Native Salesforce app · Free to install