Help Center Conditional Logic Use If/Else Conditions

Use If/Else Conditions in a Dochly Document Template

Updated June 2026 9 min read Conditional Logic
If/else conditions go beyond show/hide — they let you output different text, clauses, or entire paragraphs from a single location in the template based on a Salesforce field value. Instead of two separate sections that each hide when the other is shown, if/else keeps both outcomes in one place, making templates easier to read and maintain. This guide covers the syntax, inline switching, else-if branches, nested conditions, and a full pattern library.

Show/hide vs if/else — when to use each

Both show/hide and if/else produce conditional content — but they suit different situations. Choosing the right approach keeps templates clean and maintainable.

Use show/hide when

The conditional content is a large, standalone block — a full section, a multi-paragraph clause, or an entire page. Show/hide is simpler to configure and easier to see in the template editor. If the "false" outcome is just nothing — content either appears or it doesn't — show/hide is the right choice.

Use if/else when

You need two or more different outcomes from a single location — the same sentence outputs different text, the same clause has two versions, or a single paragraph changes based on a field. If/else keeps both (or all) outcomes together, eliminating the visual-builder complexity of managing multiple show/hide elements.

A practical rule: if you ever find yourself creating two sections with opposite show conditions ("show A when X is true" and "show B when X is false"), consolidate them into a single if/else block. It's cleaner, less error-prone, and easier to update when content changes.


Basic if/else syntax

Dochly if/else conditions use a template tag syntax inserted directly into the document content. Tags are wrapped in double curly braces and use clear keywords: {{if}}, {{else}}, {{/if}}.

// Basic if/else — two outcomes {{if StageName == "Closed Won"}} Thank you for choosing Dochly. Your order is confirmed. {{else}} This proposal is valid for 30 days from the date above. {{/if}}

The structure is always the same: opening tag with the condition, content for the true branch, {{else}} separator, content for the false branch, closing {{/if}} tag.

The else branch is optional — omitting it means nothing is output when the condition is false, which is equivalent to a show/hide condition.

// If without else — outputs nothing when false {{if Is_Renewal__c == true}} This agreement renews your existing services from {{Previous_Contract_End__c}}. {{/if}} // When Is_Renewal__c is false: no output, no blank space.

Inline text switching

The most powerful use of if/else is switching a word or phrase within a sentence — without breaking the surrounding text. The if/else tags sit inside the paragraph content and output different words depending on the field value.

Template syntax
This agreement is governed by the laws of {{if Account.BillingCountry == "Germany"}}the Federal Republic of Germany{{else if Account.BillingCountry == "France"}}the Republic of France{{else}}England and Wales{{/if}} and the parties submit to the exclusive jurisdiction of the courts of that territory.
Output — German customer
This agreement is governed by the laws of the Federal Republic of Germany and the parties submit to the exclusive jurisdiction of the courts of that territory.

The surrounding sentence structure stays identical — only the jurisdiction clause changes. Without if/else, this would require three separate sentences each with a show/hide condition — much harder to maintain and easier to accidentally introduce spacing or punctuation errors.

Inline if/else tags do not add spaces or line breaks — the output flows directly into the surrounding text. Be careful with spacing around the tags: governed by {{if ...}}German{{else}}English{{/if}} law produces "governed by German law" without a double space.


Adding else-if branches

Use {{else if}} to add a third (or fourth, fifth…) outcome between the initial if and the final else. Conditions are evaluated top to bottom — the first branch that passes is used; the rest are skipped.

// Three-tier pricing based on deal size {{if Amount >= 100000}} Enterprise pricing applies. A dedicated account manager will be assigned within 48 hours. {{else if Amount >= 25000}} Growth pricing applies. Priority support is included with your subscription. {{else}} Standard pricing applies. Support is available via the customer portal. {{/if}}

You can chain as many {{else if}} branches as needed. There is no practical limit — but deeply chained else-if logic becomes hard to read. For more than 4–5 outcomes, consider using a Salesforce formula field to pre-categorise records and simplify the template condition to a simple equals check.

// Using a formula field to simplify deep branching // Salesforce formula field: Tier__c = IF(Amount >= 100000, "Enterprise", // IF(Amount >= 25000, "Growth", "Standard")) // Simpler template condition using the formula result: {{if Tier__c == "Enterprise"}} Enterprise pricing applies... {{else if Tier__c == "Growth"}} Growth pricing applies... {{else}} Standard pricing applies... {{/if}}

Nested if/else

An if/else block can contain another if/else block — creating logic that evaluates multiple independent conditions. Use this when the outcome depends on more than one field.

// Nested: outer checks region, inner checks account type {{if Account.BillingCountry == "Germany"}} {{if Account.Type == "Enterprise"}} This agreement is subject to German law and includes full enterprise SLA terms. {{else}} This agreement is subject to German law and includes standard support terms. {{/if}} {{else}} This agreement is governed by the laws of England and Wales. {{/if}}

The outer condition evaluates first. If Germany, the inner condition evaluates next. If not Germany, the outer else runs. Every {{if}} must have a matching {{/if}} — unclosed tags are the most common source of nested condition errors.


Multi-line if/else blocks

If/else branches can contain multiple paragraphs, formatted text, merge fields, and even tables. The entire block between the opening tag and the else (or closing tag) is treated as a single unit.

// Multi-paragraph block for enterprise customers {{if Account.Type == "Enterprise"}} Premium Support is included with your Enterprise subscription. Support hours: 24/7 with a guaranteed 4-hour response time for P1 issues and next business day for all other issues. Your dedicated support contact is {{Dedicated_Support_Contact__c}}. {{else}} Standard support is provided via the customer portal at support.dochly.com during business hours, Monday to Friday, 9am–5pm GMT. {{/if}}

For very large multi-paragraph blocks, the show/hide approach (using the visual condition builder on a section element) is often cleaner than a long if/else syntax block. Reserve multi-line if/else for blocks of 3–5 paragraphs or fewer. For larger conditional sections, use show/hide on a section element.


Combining if/else with merge fields

If/else branches can contain merge fields — outputting dynamic data alongside conditional text. This allows clauses that vary both their structure and their data based on record values.

// Conditional clause with merge fields in both branches {{if Discount_Pct__c > 0}} A discount of {{Discount_Pct__c}}% has been applied to this order, reducing the total from {{List_Price__c | currency}} to {{Amount | currency}}. {{else}} This order is priced at the standard rate of {{Amount | currency}}. {{/if}}

When Discount_Pct__c is greater than 0, the clause includes the discount percentage and both list price and discounted price from the record. When there's no discount, a simpler clause with only the total appears. The document always outputs accurate, relevant pricing language — no manual editing required.


Ready-to-use if/else patterns

Inline switching

Singular vs plural noun based on quantity

Avoids "1 users" or "1 licences" in generated documents.

Your subscription includes {{Licence_Count__c}} {{if Licence_Count__c == 1}}licence{{else}}licences{{/if}}.
Clause switching

Governing law clause by billing country

Output jurisdiction-appropriate governing law language from a single template clause.

{{if Account.BillingCountry == "United States"}} This agreement is governed by the laws of the State of Delaware. {{else if Account.BillingCountry == "Germany"}} Dieses Abkommen unterliegt deutschem Recht. {{else}} This agreement is governed by the laws of England and Wales. {{/if}}
Inline switching

Payment terms text based on payment type

Outputs the correct payment due language inline within the invoice sentence.

Payment is due {{if Payment_Terms__c == "Net 30"}}within 30 days{{else if Payment_Terms__c == "Net 60"}}within 60 days{{else}}upon receipt{{/if}} of this invoice.
Nested

SLA terms — region and tier combined

Shows different SLA language depending on both the customer's region and their account tier.

{{if Region__c == "EU"}} {{if Tier__c == "Enterprise"}} EU Enterprise SLA: 99.9% uptime, 2-hour P1 response. {{else}} EU Standard SLA: 99.5% uptime, next business day response. {{/if}} {{else}} Global SLA: 99.5% uptime, 4-hour P1 response time. {{/if}}
Multi-line block

Renewal vs new customer introduction paragraph

Opens the document differently for renewal customers vs new customers — personalised without separate templates.

{{if Is_Renewal__c == true}} Thank you for continuing your partnership with us, {{Account.Name}}. This agreement renews the services from your previous contract dated {{Previous_Contract_Start__c | date: "MMMM d, yyyy"}}. {{else}} Welcome to Dochly, {{Contact.FirstName}}. We're pleased to confirm the services outlined in this agreement, effective {{StartDate__c | date: "MMMM d, yyyy"}}. {{/if}}

Common mistakes and how to avoid them

Missing closing {{/if}} tag
The most common error — every {{if}} must have a matching {{/if}}. A missing closing tag causes everything after the opening tag to be treated as part of the condition's content. Always count your opening tags against closing tags when building nested conditions.
Wrong comparison value for checkbox fields
For checkbox (boolean) fields, use {{if Field__c == true}} — not {{if Field__c == "true"}} (with quotes). The quoted version compares to the string "true", which never matches a boolean field. The unquoted version correctly evaluates the checkbox state.
Case mismatch in picklist values
Picklist comparison is case-sensitive. {{if StageName == "closed won"}} never matches "Closed Won". Always copy picklist values directly from the Salesforce picklist field definition — don't type them from memory. Check Setup → Object Manager → [Object] → Fields → [Picklist Field] → Values for the exact label text.
Double space from inline if/else tags
If you put a space before and after the if/else tags: governed by {{if ...}}German{{else}}English{{/if}} law produces "governed by German law" correctly. But governed by {{if ...}}German {{else}}English {{/if}} law (with trailing spaces inside branches) produces double spaces. Keep spaces outside the tags and omit trailing/leading spaces inside branch content when used inline.
Using == for "is blank" checks
To check if a field is empty, do not use {{if Field__c == ""}} — use the dedicated operator: {{if Field__c is blank}}. The equals-empty-string approach may not catch null values correctly across all field types. Always use the is blank / is not blank operators for null/empty checks.

Frequently asked questions

Yes. If/else syntax works inside table cells — you can switch text within a cell based on a field value. This is particularly useful in summary tables where a cell should show different labels or values depending on the deal type. Keep in-cell if/else short (a word or short phrase) — long multi-line blocks inside cells can affect table layout in the generated PDF.
Yes, using AND or OR within the condition tag: {{if Field_A == "X" and Field_B > 100}} or {{if Field_A == "X" or Field_B == "Y"}}. The and / or keywords are lowercase within the tag. You can combine up to three conditions in a single tag — for more complex logic, use nested conditions instead.
Simply omit the {{else}} entirely: {{if condition}}content{{/if}}. When the condition is false, nothing is output and no blank space is introduced. This is equivalent to a show/hide condition in the visual builder. The else branch is optional — only include it when you need a specific fallback output.
Three most likely causes: (1) A missing {{/if}} tag — the condition is not closed, so everything after the opening tag is treated as one branch; (2) The comparison value is wrong — check the exact field value on the test record and confirm case matches; (3) The field name is wrong — an incorrect field name resolves to blank, which makes conditions evaluate unexpectedly. Use the template editor's field picker to insert field names rather than typing them manually. See Troubleshooting conditional logic for a full diagnostic guide.

If/else conditions are now producing different text from the same template location. Next in this series: Create dynamic tables with conditional logic in Dochly — filter table rows, show columns conditionally, and build data-driven tables that adjust to every record.

Dochly
Salesforce AppExchange — UTECH HUB Install Dochly on AppExchange

Rated 5 stars · Native Salesforce app · Free to install