Skip to content

Instantly share code, notes, and snippets.

@diversen
Created April 18, 2023 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diversen/dd8cfb21ee10b68300063252f8869cd0 to your computer and use it in GitHub Desktop.
Save diversen/dd8cfb21ee10b68300063252f8869cd0 to your computer and use it in GitHub Desktop.
jinja2 recusive print dict
{% macro print_primitive_values(data) %}
{% if data is mapping %}
{% for key, value in data.items() %}
{% if value is mapping or value is iterable %}
<strong>{{ key }}</strong>: {{ print_primitive_values(value) }}
{% else %}
<strong>{{ key }}</strong>: {{ value }}
{% endif %}
{% endfor %}
{% elif data is iterable and data is not string %}
{% for value in data %}
{{ print_primitive_values(value) }}
{% endfor %}
{% else %}
<p>{{ data }}</p><br>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment