Jinja2Cpp icon indicating copy to clipboard operation
Jinja2Cpp copied to clipboard

"for" syntax is not work with dictionary

Open linuxpham opened this issue 5 years ago • 6 comments

Hi Admin,

{% for key, value in dict_item.items() %}

Key: {{key}}

Value: {{value}}

{% endfor %}

It is not working.

Thanks!

linuxpham avatar Oct 30 '19 06:10 linuxpham

Could you provide more detailed sample of the problem which I can add to C++/Python tests as-is?

flexferrum avatar Oct 30 '19 08:10 flexferrum

This is an example:

nlohmann::json dict_item = {"AD":"376","AE":"971","AF":"93"}; {% for key, value in dict_item.items() %} Key: {{key}} Value: {{value}} {% endfor %}

linuxpham avatar Oct 30 '19 09:10 linuxpham

I see a least one issue here. There is no user-callable 'items' in nlohmann::json reflection. I suppose, you need to replace dict_item.items() with dict_item in your sample.

What the result of this sample template processing:

{%set inner_items={"AD":"376","AE":"971","AF":"93"} %}

{% for key, value in inner_items %}
Key: {{key}}
Value: {{value}}
{% endfor %}

flexferrum avatar Oct 30 '19 11:10 flexferrum

it does not work. The result is empty! I think the "for" syntax only works with "array" data.

linuxpham avatar Oct 30 '19 20:10 linuxpham

Ok. Thanks! I'll check it out.

flexferrum avatar Nov 01 '19 11:11 flexferrum