I can't output the following json object in the jinja template engine
Abbreviated output:
{
"data": {
"domain.org": {
"type": "folder",
"children": [
{
"data": {
"type": "folder",
"children": [
{
"last-id.txt": {
"type": "file",
"children": {}
}
}
]
}
},
{
"layouts": {
"type": "folder",
"children": [
{
"_default": {
"type": "folder",
"children": [
{
"single.html": {
"type": "file",
"children": {}
}
}
]
}
},
{
"robots.txt": {
"type": "file",
"children": {}
}
}
]
}
},
{
"content": {
"type": "folder",
"children": [
{
"posts": {
"type": "folder",
"children": [
{
"post6.md": {
"type": "file",
"children": {}
}
}]
}
}]
}
}]
}
}
}
Following the example from the official documentation, I try to derive it as follows
{% set list = data['data'] %}
<ul>
{% for key in list recursive %}
<li>
{{ key }}
{% if list[key]['children'] %}
<ul>{{ loop(list[key]['children']) }}</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
I'm trying to go through the loop recursively, but nothing works, I keep getting an error:
jinja2.exceptions.UndefinedError: dict object has no element {'data': {'type': 'folder', 'children': [{'last-id.txt': {'type': 'file', 'children': {}}}]}}
How can I display such an object?