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

filters.map: apply filter to attribute ("mapattr") #1950

Open
VannTen opened this issue Apr 5, 2024 · 0 comments
Open

filters.map: apply filter to attribute ("mapattr") #1950

VannTen opened this issue Apr 5, 2024 · 0 comments

Comments

@VannTen
Copy link

VannTen commented Apr 5, 2024

Hello,

Could the map filter be able to combine both of its functionality, and apply a filter to an attribute before returning the whole structure ?

I'm often trying to use map in the following manner:
data | map(attribute='sub.key', 'somefilter', filter_args)
With data being:

data:
- key1: value
  key2: value
  sub:
    key: some_value
- key1: value
  key2: value
  sub:
    key: some_value

and expecting the result of 'somefilter' in sub.key in each element of the newly produced array.

I haven't found an easy way to achieve this with existing filters (but I might have missed something).

Obviously, this can be implemented in an extension, (I'd call that mapattr, I guess ?), but since this would be backward compatible with map (it would merely transform what is now an invalid call into a valid one : map(attribute='someattr', 'somefilter')

What do you think ? If the jinja project deems this a good idea, I can do the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant