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

Template filters first/last counterintuitive #54

Closed
phil-opp opened this issue May 1, 2017 · 4 comments
Closed

Template filters first/last counterintuitive #54

phil-opp opened this issue May 1, 2017 · 4 comments

Comments

@phil-opp
Copy link
Contributor

phil-opp commented May 1, 2017

The last filter of the tera template engine returns the last element of an array. This leads to counterintuitive results when used on an array of pages, since pages|last returns the last page in the pages array, which is actually the first/earliest page (i.e. the page with the lowest ordering). So if one follows the next pointers of a page, one reaches pages|first instead of the expected pages|last.

@Keats
Copy link
Collaborator

Keats commented May 2, 2017

Those are built-in Tera filters. I don't think it makes sense changing the behaviour because they work on the array, they have no concept of ordering. pages | first would return the earliest if sorting by date for example but pages | reverse | first would return the latest.

Changing the meaning of first and last filter would also affect any use of the filters on other arrays, which would be even more counterintuitive imo

@phil-opp
Copy link
Contributor Author

phil-opp commented May 2, 2017

pages | first would return the earliest if sorting by date

Would it? I think the array is ordered newest-first, so it would return the latest.

Changing the meaning of first and last filter would also affect any use of the filters on other arrays, which would be even more counterintuitive imo

Maybe we could order the pages array ascending (by date/order). Then pages|first would return the earliest page and pages|last the latest. We could still iterate over it in newest-first order by using the reverse filter.

@Keats
Copy link
Collaborator

Keats commented May 3, 2017

Would it? I think the array is ordered newest-first, so it would return the latest.

Yes sorry.

Maybe we could order the pages array ascending (by date/order).

I'm not sure it makes sense tbh. first and last are going to be used way less than just iterating through the pages, and in that case you want descending.
I think the current behaviour is the one that makes the most sense overall

@phil-opp
Copy link
Contributor Author

phil-opp commented May 3, 2017

first and last are going to be used way less than just iterating through the pages

Yeah, maybe you're right. It would be great if the set pages = pages | reverse syntax existed in Tera. Then everyone could just use the ordering they like.

@phil-opp phil-opp closed this as completed May 3, 2017
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

2 participants