How to PDF Template Variables
Template variables let you inject dynamic data into PDF templates without modifying the HTML itself — customer names, order totals, dates, and any other field that changes per document. SublimePDF uses Handlebars syntax for variable interpolation, giving you expressions, loops, conditionals, and helpers in a familiar, logic-light template language.
Follow the step-by-step instructions below, then use the free tool directly — no registration or download required.
Open Tool →How to PDF Template Variables — Step by Step
Define variables in your template
Insert {{ variableName }} anywhere in your HTML template where dynamic content should appear. For nested objects, use dot notation: {{ customer.address.city }}. Variables work in text nodes, attribute values, and even CSS (though CSS usage is less common).
Pass data in the API request
Include a 'data' object in your render request: { "templateId": "tmpl_abc", "data": { "customerName": "Jane Doe", "invoiceTotal": "$1,250.00" } }. Each key in the data object maps to a template variable.
Use loops for repeating content
Wrap repeating sections in {{#each arrayName}}...{{/each}}. Inside the block, {{ this.property }} accesses each item's fields. Use {{@index}} for zero-based iteration count and {{@first}} / {{@last}} for boundary detection.
Add conditionals for optional sections
Use {{#if showDiscount}}...{{/if}} to conditionally include content. {{#unless isPaid}}Payment Pending{{/unless}} inverts the condition. For equality checks, register a custom helper or use {{#ifEquals status 'completed'}} with a built-in SublimePDF helper.
Format data with built-in helpers
SublimePDF includes built-in Handlebars helpers: {{formatCurrency amount}} for locale-aware currency formatting, {{formatDate date 'MMMM D, YYYY'}} for date formatting, and {{uppercase text}} for text transformation. Pass the helper name followed by the variable.
Pro Tips
- 💡 Escape HTML in user-provided data by default — Handlebars auto-escapes {{ }} output. Use triple braces {{{ rawHtml }}} only when you intentionally want to inject unescaped HTML content.
- 💡 Use {{> partialName}} to include reusable template snippets (headers, footers, address blocks) stored as partials in your template library.
- 💡 Set default values for optional variables using the 'defaults' parameter in your render request — this prevents empty spots when a data field is missing.
- 💡 Variables inside CSS class attributes work well for conditional styling: <div class="status-badge {{ statusClass }}"> dynamically applies different CSS classes based on your data.
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 PDF Template Variables — FAQ
What templating engine does SublimePDF use?
Can I perform calculations in templates?
How do I handle missing or null variables?
Can I use variables in the header and footer templates?
Related Guides
How to Convert HTML To PDF
Converting HTML to PDF is a core workflow for developers, marketers, and anyone who needs a permanent, printable snapshot of web content. Whether you're archiving a webpage, generating reports from a web app, saving receipts from online purchases, or creating documentation from HTML templates, PDF conversion captures the visual layout, links, and styling in a portable format.
How to Generate PDF From Json
Generating PDFs from structured JSON data is the backbone of automated document workflows — invoices from order data, reports from analytics payloads, certificates from user records. SublimePDF's API accepts a JSON payload paired with an HTML/CSS template and renders a pixel-perfect PDF, letting you generate thousands of documents programmatically without any manual formatting.
How to Automate PDF Generation
Manually creating PDFs for invoices, reports, or certificates doesn't scale. Automating PDF generation through an API lets your application produce documents on demand — triggered by user actions, scheduled jobs, or webhook events. SublimePDF's REST API integrates into any tech stack (Node.js, Python, Ruby, Go, PHP) and generates PDFs from HTML templates, Markdown, or raw URLs.