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
Allow map filter to retrieve multiple items #554
Comments
Would LOVE this feature. |
I'm not clear why this is needed in templates. Just iterating over the dictionaries and using the attributes you need will accomplish the same thing. If you need different data, it's probably a better idea to do that manipulation in Python before rendering. I could maybe see a use for it returning tuples. |
If anyone still needs this you can use the following code (put in #!/usr/bin/env python
class FilterModule(object):
def filters(self):
return { 'mapattributes': self.mapattributes }
def mapattributes(self, list_of_dicts, list_of_keys):
l = []
for di in list_of_dicts:
newdi = { }
for key in list_of_keys:
newdi[key] = di[key]
l.append(newdi)
return l Use via:
|
At the moment, the map function can only be used like this:
with the return of
(Docs: http://jinja.pocoo.org/docs/dev/templates/#map)
I want to propose allowing this:
or
which should return
You can already see what this is useful for: manipulating a list of dicts so that these dicts only retain a limited set of attributes.
The text was updated successfully, but these errors were encountered: