Use If/Else Conditions in a Dochly Document Template
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.
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.
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.
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
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}}.
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}}
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.
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}}
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
{{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.{{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.{{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.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.{{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
{{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.{{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.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.
Rated 5 stars · Native Salesforce app · Free to install