Jinja2 Template Tester
Edit Jinja2 templates in file tabs with macros, includes and extends, feed them YAML or JSON variables such as Ansible group_vars, and see the output update as you type. Errors point to the file and line, Ansible filters like to_nice_yaml, combine and regex_replace are included, and a warning lists Jinja2 features the engine handles differently.
Runs in your browser. Your files never leave your device. See how to check
…
How to do it
- 1Load the engine
Press Load nunjucks to download the 26 KB engine once; an example opens straight away.
- 2Write the template
Edit the main file, add tabs for macros, includes or base layouts, and mark the file to render with Make main.
- 3Add variables
Paste YAML or JSON variables; mistakes are reported with their line before rendering.
- 4Set options
Switch trim_blocks, lstrip_blocks, autoescape and StrictUndefined to match your environment.
- 5Check the output
Read the live output, fix any error the tool points to and review the Jinja2 difference warnings.
- 6Save the result
Copy or download the rendered file, print it with the template, or save the whole project as JSON.
About this tool
Jinja2 templates sit behind Ansible roles, Salt states, dbt models, Flask and Django pages, Home Assistant automations, Airflow DAG parameters and countless configuration generators. Testing one usually means running a playbook or a Python script and reading a stack trace. This tester gives you a scratch pad instead: write the template, paste the variables and watch the rendered text. Several files can live side by side in tabs, so a main template can import macros, include partials or extend a base layout exactly as in a role's templates folder; the star marks the file that is rendered. Variables can be YAML, the format of Ansible group_vars and host_vars, or JSON, and a mistake in them is reported with its line before rendering. Rendering uses nunjucks 3.2.4, a mature JavaScript template engine modelled on Jinja2, with its Jinja compatibility mode switched on so Python-style string methods, slices and True, False and None work. On top of it the tester adds the Ansible and Jinja filters people use most: to_json, to_nice_json, to_yaml, to_nice_yaml, from_json, from_yaml, b64encode, b64decode, regex_replace, regex_search, regex_findall, combine with recursive merge, dict2items, items2dict, map with attribute, selectattr and rejectattr with tests, unique, union, intersect, difference, flatten, zip, bool, ternary, mandatory, basename, dirname, quote, comment, sum and join with attributes. Options mirror the environment settings that change output: trim_blocks, lstrip_blocks, autoescape and StrictUndefined. Because nunjucks is close to Jinja2 but not identical, a linter flags constructs that would behave differently, so you know what to double-check in Python.
How close is it to real Jinja2?
Expressions, filters, tests, if, for with else and the loop variables index, index0, revindex, first, last and length, set and block set, macros with arguments and caller, import, from import, include, extends with blocks and super, raw blocks and whitespace control with minus signs behave as in Jinja2 for everyday templates. The differences we know of are listed in the Filters and differences tab and flagged in your template: there is no do or with statement, no break and continue, no loop.cycle, previtem, nextitem or changed, no Python % formatting or str.format, and a few filters (wordwrap, xmlattr, filesizeformat) are missing. Numbers follow JavaScript, so very large integers and some float rounding can differ.
Tested against
The examples on this page (an nginx config with a macro, an /etc/hosts file, an HTML email with extends, a dbt-style SQL model) were rendered with nunjucks 3.2.4 during development, and our added filters have their own unit tests. They were not rendered with Python Jinja2 or a real Ansible run, so output can differ in whitespace, number formatting and the features listed above.
Ansible notes
Lookups and filters that read files, hash passwords or contact services do not run in a browser and stop with a clear message. Ansible facts are not gathered, so paste the facts your template needs into the variables.
Engine download
nunjucks is about 26 KB and loads from jsDelivr pinned to version 3.2.4 when you press Load. Templates and variables never leave the page.
Limits
This is a testing aid, not a replacement for running the real playbook. Always render production templates once with the Python Jinja2 version your tools use.
Worked example
A platform engineer edits an nginx.conf.j2 for three upstream servers, one marked disabled: true, plus two security headers in a dictionary. With trim_blocks and lstrip_blocks on, the output shows an upstream block with two server lines (the disabled host is removed by rejectattr), listen 8080 and 443 ssl because enable_tls is true, two add_header lines produced by a macro from macros.j2 in alphabetical order through dictsort, and a comment listing app1, app2, old (3 total). Switching StrictUndefined on and misspelling http_port as http_prot stops the render at line 10 of nginx.conf.j2, the same mistake Ansible would report during the play.
Quick facts
- Category: Developer & Data
- Works in your browser, no sign-up, no upload.
- Your input stays on your device.
- Available in English.
- Content last reviewed:
- Official source: Jinja 3.1 Template Designer Documentation, Ansible filter documentation, and nunjucks 3.2.4 (BSD-2-Clause) templating documentation
Frequently asked questions
Is this real Jinja2?
It renders with nunjucks 3.2.4 in Jinja compatibility mode, a JavaScript engine that implements the Jinja2 template language closely. Everyday templates give the same output; the tool lists and flags the features that differ, so confirm unusual templates with Python Jinja2.
Can I test Ansible templates with group_vars?
Yes. Paste the YAML from group_vars or host_vars into the variables tab, add facts your template uses by hand, and the common Ansible filters such as to_nice_yaml, combine, regex_replace and dict2items are available.
Do macros, include and extends work?
Yes. Add more file tabs with + File, give them the names your template uses, and import, include and extends find them. The starred file is the one rendered.
What do trim_blocks and lstrip_blocks change?
trim_blocks removes the first newline after a block tag and lstrip_blocks removes spaces before a block tag on its line. Ansible switches trim_blocks on by default, so leave it on to match Ansible output.
Why do I get an error about an undefined variable?
With StrictUndefined on, any variable that is not in your data stops the render with its file and line, like Ansible's error. Turn it off to render missing values as empty text instead.
Are my templates uploaded?
No. Only the engine file is downloaded once from jsDelivr; your templates, variables and output stay in the browser and in your saved projects.
