You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yesterday I ran into an issue trying to use some of Nunjucks builtin filters
According to the Jinja docs the sort filter is able to accept keyword arguments for sorting arrays of objects
{% for post in posts|sort(attribute="date") %}
<h3>{{ post.title }} <small>{{post.date}}</small></h3>
{% endfor %}
Which simply leaves the array of blog posts unsorted. Taking a quick look at the tests for sort it looks like filters don't support keyword arguments but this does work ...
{% for post in blog|sort(false, false, "title") %}
<h3>{{ post.title }} <small>{{post.date}}</small></h3>
{% endfor %}
So my question is should the built in filters be documented in the Nunjucks site (rather then just linking to Jinja) I could move all the docs easily. Or should filters be modified to accept keyword arguments?
The text was updated successfully, but these errors were encountered:
We've been meaning to document our filters and not rely on jinja's documentation. If someone wants to start that work, that would be great. And yes, we could probably improve sort by using keyword arguments (support already exists)
jlongster
changed the title
Supporting keyword arguments for filters
Supporting keyword arguments for sort filter
Apr 28, 2015
Yesterday I ran into an issue trying to use some of Nunjucks builtin filters
According to the Jinja docs the
sort
filter is able to accept keyword arguments for sorting arrays of objectsWhich simply leaves the array of blog posts unsorted. Taking a quick look at the tests for sort it looks like filters don't support keyword arguments but this does work ...
So my question is should the built in filters be documented in the Nunjucks site (rather then just linking to Jinja) I could move all the docs easily. Or should filters be modified to accept keyword arguments?
The text was updated successfully, but these errors were encountered: