Skip to main content

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 NameCost
{% for item in items %} {{ item.name }}{{ item.cost }} {% endfor %}

(The entire row will replicate for each item).

Images

  1. Add a placeholder image in your Word doc.
  2. In the "Alt Text" description of the image, put the token: {{ img_key }}.
  3. Pass img_key as 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

  1. Use Snake Case: {{ client_name }} is better than {{ Client Name }}.
    • Note: Our system auto-corrects spaces to underscores, but explicit is better.
  2. Test with JSON: Use the "Generate > Single" tab to test complex structures (lists, nested objects) before trying Bulk Generation.
  3. PDF vs DOCX:
    • DOCX Output: Editable, perfect for drafts.
    • PDF Output: Read-only, verified layout, great for final delivery.