Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"for" syntax is not work with dictionary #178

Open
linuxpham opened this issue Oct 30, 2019 · 5 comments
Open

"for" syntax is not work with dictionary #178

linuxpham opened this issue Oct 30, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@linuxpham
Copy link

Hi Admin,

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

Key: {{key}}


Value: {{value}}


{% endfor %}

It is not working.

Thanks!

@flexferrum
Copy link
Collaborator

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

@flexferrum flexferrum added the investigation needed Looks like bug or issue, but some investigation needed label Oct 30, 2019
@linuxpham
Copy link
Author

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 %}

@flexferrum
Copy link
Collaborator

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 %}

@linuxpham
Copy link
Author

linuxpham commented Oct 30, 2019

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

@flexferrum
Copy link
Collaborator

Ok. Thanks! I'll check it out.

@flexferrum flexferrum added enhancement New feature or request and removed investigation needed Looks like bug or issue, but some investigation needed labels Mar 15, 2020
@flexferrum flexferrum added this to To Do in Jinja2Cpp standard features via automation Mar 15, 2020
@flexferrum flexferrum added this to the Release 1.2 milestone Mar 15, 2020
@flexferrum flexferrum removed this from the Release 1.2 milestone Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants