Assuming I have something like:
{{#each pageElements}}
{{#is pageElement "news"}}
{{#withSort pages "data.posted" dir="desc"}}
<a href="/{{relativeLink}}">
{{formatDate data.posted "%d.%m.%Y"}}: {{data.title}}
</a>
{{/withSort}}
{{/is}}
{{/each}}
How would I only show the first item that withSort
spits out?
I'm think I can use the first
collection helper for this (http://assemble.io/helpers/helpers-collections.html) but I haven't been able to get the syntax right.
The helpers in handlebars-helpers that were built for
grunt-assemble
don't handle some of the things that you'd want to do for this specific case.We're working on getting the dev branch published and some of these will be easier to use with handlebars subexpressions.
For now, you will probably want to make your own helper that does the sorting, then you can use
first
:Make a
sort.js
helper file:Register the helper with assemble and use in the template:
This should get what you need. Hope it helps.