Why templates?
Templates separate layout from data. Define your HTML once, then render it with different data on every API call. This means:- No HTML in your application code. Your app sends JSON data, not markup.
- Version control. Templates are stored and versioned by PDFBase.
- Schema validation. Bad data is caught before rendering, not after.
- Faster renders. Templates are pre-parsed and cached.
Creating a template
A template has three parts: HTML (with Handlebars placeholders), schema (expected data shape), and defaults (rendering options).Handlebars syntax
Variables
Loops
Conditionals
Built-in helpers
Schema validation
The schema defines what data the template expects. When you render, PDFBase validates the data against the schema first:Supported types
If the data doesn’t match, you get a
422 with specific field-level errors before any rendering happens.
Templates-as-code (CLI)
Instead of managing templates through the API, use the CLI to push templates from your repo:Project structure
pdfbase.json
Push and preview
Rendering a template
Versioning
Every time you update a template (via APIPATCH or CLI push), the version increments. Each rendered PDF records which version was used: