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

Add Nunjucks filter to filter an array of data depending on the values of properties within it. #715

Closed

Conversation

gonogo
Copy link

@gonogo gonogo commented Mar 20, 2019

Examples of usage:

  • {% for tx in data.transactions | filterObjects('type', 'is not', 'submission') | sort(true, false, 'lastUpdated') %}
  • {% for tx in data.users | filterObjects('role', 'is', 'admin') %}

Thanks to @igloosi for this contribution.

Examples of usage:
- {% for tx in data.transactions | filterObjects('type', 'is not', 'submission') | sort(true, false, 'lastUpdated') %}
- {% for tx in data.users | filterObjects('role', 'is', 'admin') %}
@NickColley
Copy link
Contributor

As I mentioned in the previous pull request we've not currently got clear evidence that our users need this feature.

I'm going to close this out for now, but will use it as a reference if we get more people asking for this, then we can re-open :)

Thanks again.

@NickColley NickColley closed this Mar 20, 2019
@edwardhorsford
Copy link
Contributor

I created a similar filter to this recently - I wanted to filter an array of objects to only those that had an attribute of a certain value. It would have been useful to have it built in.

Mine only tested for whether the value equals the test item:

// filter results for only those containing attr/ var
  filters.filterAttr = function (arr, attr, test) {
    var result = arr.filter(function (item) {
       return item[attr] === test;
    });
    return result
  };

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

Successfully merging this pull request may close these issues.

3 participants