Templates Guide
DocGenLab supports two types of templates: DOCX (Microsoft Word) and HTML. Both use Jinja2-style syntax for dynamic content.
1. DOCX Templates (Word)
Upload a .docx file created in Microsoft Word. This is the best option for high-fidelity legal documents, letters, and reports.
Basic Syntax
Use double curly braces to insert variables.
- Text:
{{ client_name }} - Formatted:
{{ amount | round(2) }}(Standard Jinja2 filters work!)
Conditional Logic
Hide or show sections of text based on data.
{% if is_paid %}
PAID IN FULL
{% else %}
Please remit payment by {{ due_date }}
{% endif %}
Loops (Lists & Tables)
To repeat a bullet point or table row, use a for loop.
In a Table Row:
Place {% tr for item in items %} at the start of the row and {% entr %} at the end (or standard Jinja tags inside the first/last cells depending on complexity).
Recommended approach for simpler tables:
| Item Name | Cost |
|---|---|
{% for item in items %} {{ item.name }} | {{ item.cost }} {% endfor %} |
(The entire row will replicate for each item).
Images
- Add a placeholder image in your Word doc.
- In the "Alt Text" description of the image, put the token:
{{ img_key }}. - Pass
img_keyas a URL or Base64 string in your data.
2. HTML Templates
Create templates directly in our Template Builder. Best for simple invoices, emails, or web-native layouts.
Syntax
Same Jinja2 syntax applies.
<div class="header">
<h1>Invoice #{{ invoice_number }}</h1>
</div>
{% if premium %}
<div class="badge">Premium Member</div>
{% endif %}
<table>
{% for item in items %}
<tr>
<td>{{ item.name }}</td>
<td>${{ item.price }}</td>
</tr>
{% endfor %}
</table>
Rich Media Helpers
DocGenLab includes built-in helpers to generate dynamic media. These work in both DOCX and HTML templates.
QR Codes
Generate a QR code on the fly.
{{ insert_qr('https://google.com', size=100) }}
Barcodes
Generate industrial barcodes (Code128, etc).
{{ insert_barcode('123456789', format='code128') }}
Google Maps
Insert a static map image for a location.
{{ insert_map('Times Square, NY', zoom=13) }}
Best Practices
- Use Snake Case:
{{ client_name }}is better than{{ Client Name }}.- Note: Our system auto-corrects spaces to underscores, but explicit is better.
- Test with JSON: Use the "Generate > Single" tab to test complex structures (lists, nested objects) before trying Bulk Generation.
- PDF vs DOCX:
- DOCX Output: Editable, perfect for drafts.
- PDF Output: Read-only, verified layout, great for final delivery.