How to Conditional PDF Content
Not every document should show the same content to every recipient. Conditional content lets you show or hide sections, swap languages, apply discount blocks, toggle compliance disclaimers, or personalize layouts — all from a single template driven by your data. SublimePDF's Handlebars-based templates support conditionals that keep your template library lean instead of maintaining dozens of near-identical templates.
Follow the step-by-step instructions below, then use the free tool directly — no registration or download required.
Open Tool →How to Conditional PDF Content — Step by Step
Use basic if/else blocks
Wrap conditional sections in {{#if condition}}...{{else}}...{{/if}}. The condition is truthy when the value exists, is non-empty, and isn't false or 0. Example: {{#if isPremiumCustomer}}<div class='premium-badge'>Premium</div>{{/if}}.
Check for specific values with helpers
Use the built-in {{#ifEquals}} helper for value comparisons: {{#ifEquals paymentStatus 'overdue'}}<span class='overdue-alert'>Payment Overdue</span>{{/ifEquals}}. This is cleaner than nested if-else chains for multi-value checks.
Toggle entire page sections
Wrap large sections (appendices, terms and conditions, optional product pages) in conditional blocks. Use CSS with break-before: page inside the conditional block to start that section on a new page only when it's included.
Apply conditional CSS classes
Dynamically assign CSS classes based on data: <tr class="{{#if isOverdue}}row-overdue{{else}}row-normal{{/if}}">. This lets you change colors, fonts, and layouts without duplicating HTML structure.
Nest conditions for complex logic
Conditions can nest: {{#if hasDiscount}}{{#if isAnnualPlan}}Annual discount applied{{else}}Monthly discount applied{{/if}}{{/if}}. Keep nesting to two levels maximum — deeper nesting makes templates hard to maintain.
Pro Tips
- 💡 Use {{#unless}} as a cleaner alternative to {{#if}} with negation — {{#unless isPaid}}Payment Required{{/unless}} reads better than an if-else with an empty if block.
- 💡 For multi-language templates, use a top-level 'locale' variable with nested conditionals: {{#ifEquals locale 'fr'}}Facture{{else}}Invoice{{/ifEquals}}. Alternatively, pass already-translated strings in your data object for cleaner templates.
- 💡 Conditional blocks that hide large sections (pages of content) still reduce the PDF page count, so your document dynamically adjusts length based on the data — no manual pagination needed.
- 💡 Test every conditional branch by rendering the template with different data payloads — it's easy to miss a broken {{else}} path that's rarely triggered in production.
Privacy & Security
All processing happens directly in your browser. Your files are never uploaded to any server — they remain on your device throughout the entire process. SublimePDF uses WebAssembly technology for fast, secure, client-side processing.
Works Everywhere
This tool works on any modern browser — Chrome, Firefox, Safari, or Edge — on desktop, tablet, or mobile. No software to install. PDF is an open ISO standard supported by all major platforms.
How to Conditional PDF Content — FAQ
Can I show different content to different users with one template?
How do I conditionally include an entire page?
What counts as 'falsy' in Handlebars conditionals?
Can I compare two variables to each other?
Related Guides
How to Redact PDF Content
Redaction permanently removes sensitive information—Social Security numbers, financial details, medical records, confidential names—from a PDF so it cannot be recovered. Unlike drawing a black box over text, proper redaction deletes the underlying data entirely. This is legally required for FOIA responses, court filings, and HIPAA compliance. SublimePDF performs true redaction that erases content from the file, not just covers it visually.
How to Add Page Numbers to PDF
Adding page numbers to a PDF makes documents easier to navigate and reference. Whether it's a report, manuscript, or legal document, SublimePDF lets you add customizable page numbers in seconds.
How to Convert Scanned PDF to Text
Scanned PDFs are essentially images — you can't select or search the text. OCR (Optical Character Recognition) technology converts these image-based PDFs into searchable, editable text. SublimePDF's OCR tool handles this conversion right in your browser.