Skip to main content

Introduction to Jinja2

APITemplate.io uses Jinja2 as its template language. If you've used Python or similar templating systems, you'll feel right at home. If not, don't worry — it's straightforward to learn.

Jinja2 lets you combine an HTML template with JSON data to produce dynamic output. You write your template once with placeholders, and the values get filled in every time you generate a document.

How it works

Template rendering overview

You have two ingredients:

  1. A template — HTML with special placeholders
  2. JSON data — the values to fill in

When you render the template, Jinja2 replaces the placeholders with your data.

Example

JSON data:

{
"product": "Apple Juice",
"made_in": "Singapore"
}

Template:

The product is {{product}}, made in {{made_in}}.

Output:

The product is Apple Juice, made in Singapore.

Jinja2 syntax at a glance

There are three main delimiters you'll use:

SyntaxPurposeExample
{{ ... }}Output a variable or expression{{ name }}
{% ... %}Control flow (if, for, etc.){% if active %}...{% endif %}
{# ... #}Comments (not rendered){# This is a note #}

What you can do with Jinja2

  • Variables — insert dynamic text, numbers, dates
  • Conditions — show or hide content based on data
  • Loops — repeat sections for lists and arrays
  • Filters — transform data (uppercase, format currency, render QR codes)
  • Date formatting — parse and format dates and timestamps

Next steps

tip

You can learn the full Jinja2 syntax from the official Jinja2 documentation. APITemplate.io supports all standard Jinja2 features, plus custom filters for QR codes, barcodes, and tables.