jaredly / jaredly/hexo-renderer-handlebars
Iterating over posts complicated
- Dominant language
- JavaScript
- Stars
- 25
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
Just for curiosity: how do you iterate over page.posts/site.posts/tags, ...? After trying a lot of different ways, I ended up with two possibilities:
```
{{#with page.posts}}
{{#each ../page.posts.toArray}}
...
{{/each}
{/with}}
```
This works if you don't want to limit posts; you will iterate over all of them (can't change ordering either). Other possiblity: create a helper which converts query objects to an array:
```
{{#each (to_array page.posts) }}
...
{{/each}}
```
or
```
{{#each (to_array get_posts count=3 order=date) }}
...
{{/each}}
```
I would suggest adding this "to_array" as a standard helper. Any other possibilities?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing how page.posts, site.posts, tags, and get_posts are exposed to Handlebars templates, then locate the standard helper registration entry point. Check whether a to_array helper can preserve the shown ordering and count options, and define done as allowing the example each expressions to iterate over query objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- handlebars, javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100