I want to display a list of max 3 posts from a certain tag on the homepage (index.hbs) but exclude any posts previously displayed in the main stream of posts.
I am trying to replicate what is described here:
No posts are being displayed when using the exact code above with index.bhs. It works as expected in post.hbs. Have there been any changes with Ghost 2 that prevent the use of this like described?
Nothing has changed in 2.0 that breaks this behaviour and it is still working as expected for me.
I would suggest that where it has gone wrong is to do with ensuring that the path used to access IDs is not correct relative to where you’re calling the code in your theme. {{posts[*].id}} and {{post.id}} are relative paths which are navigating the JSON data associated with the template, so if you’re inside either {{#foreach posts}} or {{#post}} or inside any other block, you’d need to adjust the path to work correctly.
If you share some theme code we can help you adjust the paths.
When I implement the code referenced on a single post, it seems to work fine. It is just on the front page of the blog that I do not get the expected results. I first get all featured posts from category X, next I get all posts from category X but skipping the previously loaded post from the first loop.
Every template you work with in Ghost, e.g. post.hbs or index.hbs has an associated JSON “blob” - a bunch of data that we prefetch for you.
There is a context table in the docs that shows you for each potential URL what template is used by default and what the structure of the associated JSON blob looks like.
In addition to that blob, you can fetch any data you like using the get helper, as you are doing.
You still need to be aware of the existing JSON blob so that you can understand namespaces of data, and how to access it.
Inside {{#get "posts"...}}...{{/get}}, the results from that data fetch are referred to by default with the key posts, unless you explicitly provide it with a different name.
On index.hbs, that naming clashes with the default posts list.
In the code you’ve provided, posts[*] in the second {{#get}} block is referring to the default list of posts, not the list of posts fetched by the first request.
Can two id filters be combined - for example if I wanted to do id:-[{{posts[*].id}}] and id:-{{id}} both at once? I tried all obvious combinations and none seems to work.