Paste a Jinja2 template and its variables in YAML or JSON and see the rendered result as you type. It runs the real Jinja2 library (Python, via Pyodide) inside your browser, so whitespace, filters and error messages match what you get in Ansible, Flask or Salt.
Last updated:
Ctrl + Enter renders
Advertisement
Advertisement
How to use the Jinja2 Template Tester
Pick an example or paste your template into the Template box (for example an Ansible .j2 file).
Enter the variables as YAML or JSON in the Variables box. The top level must be key: value pairs.
Choose the flavor: Plain Jinja2, Ansible (extra filters, strict undefined, trim_blocks) or Flask (autoescape).
Read the output. It updates as you type; turn on Show whitespace to see stray spaces and blank lines.
Fix any error using the highlighted line number and hint, then copy or download the rendered text.
{{ users | selectattr('active') | map(attribute='name') | list }}
names of active users
groupby
{% for k, items in rows | groupby('region') %}
rows grouped by region
dictsort
{% for k, v in cfg | dictsort %}
dictionary items sorted by key
format
{{ '%.2f' | format(3.14159) }}
3.14
indent
{{ block | indent(4) }}
indents every line after the first by 4 spaces
tojson
{{ data | tojson }}
HTML-safe JSON for scripts
truncate / wordcount
{{ text | truncate(20) }}
shortened text ending in ...
Tips for debugging templates
Turn on strict undefined while testing. A misspelled variable then raises an error with its line number instead of printing nothing.
Watch out for dict method names. Keys called items, keys, values or get must be read with brackets: data['items'].
Variables set inside a loop do not survive the loop. Use namespace() for counters and totals.
Use | int or | float before math on values that come from YAML strings or Ansible facts.
Only mark trusted HTML as safe. With autoescape on, | safe prints raw HTML, which can let untrusted input inject markup.
Frequently asked questions
Is this the real Jinja2 or a JavaScript imitation?
It is the real Jinja2 Python library. The page loads Pyodide, a build of Python for the browser, together with the official Jinja2 and PyYAML packages, and renders your template with them. The first load downloads about 10 MB from a public CDN; after that your browser caches it. Your template and variables never leave your device.
Can I test Ansible templates here?
Yes. Choose the Ansible flavor: it turns on trim_blocks and keep_trailing_newline like the template module, makes undefined variables an error, and adds common Ansible filters such as to_nice_yaml, to_json, regex_replace, regex_search, combine, dict2items, ternary, bool, b64encode, basename and flatten. Ansible lookups, facts and plugins are not available, so define facts like ansible_hostname yourself in the variables.
Why does my output have extra blank lines?
Every {% … %} tag leaves the newline that follows it. Turn on trim_blocks to remove the first newline after a block tag, lstrip_blocks to remove indentation before it, or add a minus sign inside the tag, as in {%- if x -%}, to strip whitespace on that side. Show whitespace marks spaces with dots and line ends with ¶.
What happens with undefined variables?
With the default setting an undefined variable renders as an empty string, which can hide typos. Strict raises an UndefinedError with the line number, as Ansible does. Chainable lets you write a.b.c on missing values without errors, and Debug prints the placeholder, for example {{ missing_var }}. The chips under the output list each variable the template uses and mark the ones you have not defined.
Why do I get 'builtin_function_or_method' object is not iterable?
Your data has a key named items, keys or values, and order.items finds the Python dict method instead of your list. Write order['items'] instead, or rename the key. The same applies to other dict method names such as update, get or pop.
Why is YAML yes or on turned into true?
The variables are read with PyYAML, which follows YAML 1.1, the same rules Ansible uses. In YAML 1.1 yes, no, on and off are booleans. Quote the value ("yes") if you need the text.
Does it support macros, includes and template inheritance?
Macros, call blocks, filters, tests, loops with loop.index, set with namespace(), do and break/continue all work in the single template you test. include, import and extends need other template files, which this tester does not have, so put macros in the same template or paste the parent template's content in.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.