pallets / jinja

A very fast and expressive template engine.

Home Page:https://jinja.palletsprojects.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make class Namespace iterable

joeUser555 opened this issue · comments

The namespace feature is very handy to define local objects similar to a dictionary.
Unfortunatly they are not iterable, thus making them unusable in for-loops like " {% for k,v in namespaceObject %}..."

I tryed to implement the iter method in the class Namspace in jinja2/utils.py.
But I did not understand the implementation concept of that class so I faild.

Perhaps someone from the team can do that.
It should not be so complicated from the view that a namspace object is acting like a dictionary object.

The iterator should yield only the items that are directly defined in it.
It should not yield items from posible parent namespaces.

This is not an intended use case for namespace. It is intended only for tracking and accessing data between loop iterations.

That sounds plausible.