Debugging Template Logic
When your template doesn't produce the expected output, here are some techniques to figure out what's going on.
Common issues and fixes
Variable not showing up
If {{my_variable}} renders as blank, check these things:
- Is the variable name correct? — variable names are case-sensitive.
{{Name}}and{{name}}are different - Is it in your JSON? — open the Sample JSON tab and make sure the key exists
- Is it nested? — if your JSON has
{"user": {"name": "Mike"}}, use{{user.name}}, not{{name}} - Is it empty? — the variable might exist but have an empty value. Use
{{ my_var | default("MISSING") }}to confirm
Template syntax error
If you see an error when rendering, look for:
- Unclosed tags — every
{% if %}needs{% endif %}, every{% for %}needs{% endfor %} - Missing braces — make sure you have
{{and}}(two of each) - Typos in tag names —
{% fore %}instead of{% for %}
Loop not rendering
If a {% for %} loop produces no output:
- Check that the variable is actually a list/array in your JSON
- Make sure the JSON array isn't empty
- Verify you're using the correct variable name
Debugging techniques
Print raw JSON
Output the raw JSON value to see what data you're working with:
<pre>{{ my_variable | json }}</pre>
This renders the variable as formatted JSON, which helps you see the structure.
Use default filter to detect missing values
<p>Name: {{ name | default("** NOT SET **") }}</p>
<p>Email: {{ email | default("** NOT SET **") }}</p>
<p>Items count: {{ items | length | default(0) }}</p>
Check variable type
If you're not sure what type a variable is, output it in different ways:
<p>Raw value: {{ my_var }}</p>
<p>Length: {{ my_var | length }}</p>
<p>As JSON: {{ my_var | json }}</p>
Test conditions step by step
If a complex condition isn't working, break it into parts:
<!-- Instead of this: -->
{% if user.role == "admin" and user.active and items | length > 0 %}
<!-- Test each part separately: -->
<p>Role: {{ user.role }}</p>
<p>Active: {{ user.active }}</p>
<p>Items count: {{ items | length }}</p>
Quick Preview vs Generate PDF
Quick Preview (Ctrl+Q) renders the HTML in the browser instantly. It's great for checking template logic quickly, but it doesn't include headers, footers, or PDF-specific settings.
Generate PDF produces the actual PDF file with all settings applied. Use this to verify the final output, including page breaks, margins, and headers/footers.
Use Quick Preview for rapid iteration and Generate PDF for final verification.
Getting help
If you're stuck:
- Double-check your JSON structure in the Sample JSON tab
- Review the Jinja2 documentation for syntax details
- Reach out to support — the team is responsive and happy to help