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
Nunjucks' goal is to have full Jinja2 compatibility, and eventual Twig compatibility.
The Twig slice filter behaves a lot like Javascript's arr.slice(start, end), however Jinja's slice creates an array of arrays.
In effect, it can be argued that Nunjucks is missing a feature to get n items from the start/end of a string/array because in Python Jinja2, this can be achieved using the square bracket notation source_list[:N]. Given that Nunjucks does not allow this, a better proposal IMO would be to "augment" the first and last filters so they can take an additional signature with an argument, like:
The following is salvaged from a meaningful comment on a now-deleted PR that is a good candidate for increased feature parity
This is really easy to add in user-code if desired:
Nunjucks' goal is to have full Jinja2 compatibility, and eventual Twig compatibility.
The Twig slice filter behaves a lot like Javascript's
arr.slice(start, end)
, however Jinja's slice creates an array of arrays.In effect, it can be argued that Nunjucks is missing a feature to get n items from the start/end of a string/array because in Python Jinja2, this can be achieved using the square bracket notation
source_list[:N]
. Given that Nunjucks does not allow this, a better proposal IMO would be to "augment" thefirst
andlast
filters so they can take an additional signature with an argument, like:Originally posted by @webketje in #1366 (comment)
The text was updated successfully, but these errors were encountered: