Reusable Template Components with Snippets and Partials
Last updated March 23, 2026
PDFMonkey gives you two ways to reuse code and avoid duplication:
- Snippets are shared across templates — define them once on the Snippets page and include them in any template.
- Partials are local to a single template — define a reusable block inline and include it multiple times in the same template.
Both use the include tag to render the reusable block with the variables you pass.
Snippets
If you need to share code between Templates, you can define snippets in the Snippets page of your PDFMonkey account. The name you give a Snippet is how you will refer to it later on in your Templates.
Let’s define two snippets:
{%- if userName -%}
{{userName}}
{%- else -%}
Someone
{%- endif -%}
{%- for item in list -%}
<p>{{item}}</p>
{%- endfor -%}
You can then load and include them in a Template:
{%- load_snippets 'user-name', 'items-list' -%}
<p>Hello {% include 'user-name', userName: "Jane Doe" %}</p>
{% include 'items-list', list: user.groceries %}
load_snippets before you can include them. List all the snippets you need in a single load_snippets call at the top of your template.Partials
Partials work like Snippets but are defined directly within a Template. You don’t need to load them before including them:
{%- partial 'line-item' -%}
<tr>
<td>{{product.name}}</td>
<td>{{product.unitPrice}}</td>
<td>{{product.quantity}}</td>
<td>{{product.totalPrice}}</td>
</tr>
{%- endpartial -%}
{% for lineItem in lineItems %}
{% include 'line-item', product: lineItem %}
{% endfor %}
Partials are ideal when you need to repeat a block within a single template — like a table row, a card layout, or any recurring element — without the overhead of creating a shared Snippet.
Frequently asked questions
- How do I reuse code across multiple PDFMonkey templates?
- Use Snippets. Define reusable code blocks on the Snippets page of your PDFMonkey account, then load them in any template with the load_snippets tag and include them with the include tag.
- What is the difference between Snippets and Partials in PDFMonkey?
- Snippets are shared across templates — define them once and include them in any template. Partials are local to a single template — define a reusable block inline and include it multiple times within the same template.
- How do I pass variables to a Snippet or Partial in PDFMonkey?
- Pass variables as key-value pairs in the include tag. For example: {% include ‘user-name’, userName: “Jane Doe” %}. The Snippet or Partial can then use those variables in its Liquid code.