Appearance
Template and Payload
Press supports splitting a document into two parts: a template that defines the design, and a payload that provides the content. This separation is the key to using Press at scale -- store a template once and generate thousands of documents by sending different payloads.
How It Works
A template contains the layout, styles, components, and page definitions:
xml
<!-- Template: stored on the platform -->
<press>
<document format="A4" page-margin="2cm">
<page>
<frame direction="row" space-after-desired="24pt">
<frame width="fill">
<frame font-size="10pt">To: {{ data.recipient }}</frame>
<frame font-size="10pt">Date: {{ data.date }}</frame>
</frame>
<img src="logo" max-height="40pt" />
</frame>
<flow name="body" />
<frame space-before-desired="24pt">
<p>Yours sincerely,</p>
<p font-style="bold">{{ data.sender }}</p>
</frame>
</page>
</document>
<assets>
<images>
<logo>https://examples.papermill.io/papermill_logo.png</logo>
</images>
</assets>
<styles>
<document>
<font>Inter</font>
<font-size>10pt</font-size>
<line-height>1.5</line-height>
</document>
</styles>
</press>A payload provides just the parts that change:
xml
<!-- Payload: sent via API -->
<press>
<flows>
<body type="markdown">
Thank you for your application to the Graduate Programme.
I'm delighted to confirm that you have been accepted. Your start
date is 1 September 2026. Please find enclosed the onboarding
documents for your review.
We look forward to welcoming you to the team.
</body>
</flows>
<data type="json">
{
"recipient": "Dr. A. Patel",
"sender": "R. Whitfield, HR Director",
"date": "15 January 2026"
}
</data>
</press>Merging Rules
When Press receives both a template and a payload, it merges them:
| Top-Level Element | Merge Behaviour |
|---|---|
<flows> | Payload flows replace template flows with the same name. New flows are added. |
<data> | Deep-merged. Objects merge key by key; any other payload value replaces the template's. |
<components> | Merged. Payload components are added to or override template components. |
<styles> | Template styles are used. Payload styles are merged in. |
<assets> | Template assets are used. Not presently overridden by payloads. |
<document> | Template document structure is used. Not overridden. |
<pages> | Template page definitions are used. Not overridden. |
Data Merging in Detail
Papermill merges the payload's data over the template's, key by key at every level:
- An object in the payload merges into the template's object of the same name, so you can send only the nested keys that change.
- Any other payload value — an array, string, number, boolean or
null— replaces the template's value whole. Arrays are not merged item by item: send every item you want rendered. - A key the payload leaves out keeps the template's value.
Template:
json
{
"currency": "£",
"company": { "name": "Default Corp", "city": "London" },
"items": [
{ "name": "Setup", "price": 100 },
{ "name": "Support", "price": 50 }
]
}Payload:
json
{
"company": { "name": "Meridian Consulting" },
"items": [{ "name": "Audit", "price": 1800 }],
"client": "Helena Torres"
}Result:
json
{
"currency": "£",
"company": { "name": "Meridian Consulting", "city": "London" },
"items": [{ "name": "Audit", "price": 1800 }],
"client": "Helena Torres"
}company.name comes from the payload and company.city keeps the template's value. The payload's one-item items replaces both template items. currency keeps the template's value, and client is added.
To clear a template value, send it as null; leaving the key out keeps the template's value.
Expressions in Data
Expressions in the template's top-level <data> resolve after the payload's data merges in, so a template value can use a payload value:
json
{ "title": "Invoice for {{ data.client }}" }With the payload above, data.title is Invoice for Helena Torres. A value can refer to another value that holds an expression, in any order. Papermill rejects the document if a chain of references leads back to where it started.
A payload carries values, not expressions: Papermill rejects a payload whose data holds {{ … }}. Compute the value before you send it, or put the expression in the template. The Playground is the exception: it renders a template's sample data as you edit it, expressions included. An API or MCP call that sends the same data is rejected, so send values from your integration.
Using Template and Payload via the API
- Create your template on the Papermill platform
- Copy the template ID from the editor URL
- Send a payload via the API with the template ID:
javascript
const payload = `
<press>
<flows>
<body>Thank you for your application...</body>
</flows>
<data>
<recipient>Dr. A. Patel</recipient>
<sender>R. Whitfield</sender>
<date>15 January 2026</date>
</data>
</press>
`
const response = await fetch(`https://api.papermill.io/v2/pdf?template=${templateId}`, {
method: 'POST',
headers: {
'Content-Type': 'text/xml',
'X-API-Key': apiKey,
},
body: payload,
})Benefits
- Designers control the template: layout, fonts, colours, page structure
- Developers control the payload: content, data, conditional sections
- AI models can generate markdown payloads without needing to understand the template structure
- One template generates unlimited variations by changing the payload
Best Practices
Put defaults in the template. If most invoices use GBP, set "currency": "£" in the template's <data>. Payloads only need to override it when the currency differs.
Use asset data for constants. Values that should never change (company logos, legal text) go in <assets><data>. These aren't affected by payload merging.
Keep payloads minimal. Only send the data and flows that change. The template handles everything else.
Use markdown flows for AI-generated content. AI models produce clean markdown. The template handles all formatting and layout.