page.posts is not site.posts
Closed this issue · 5 comments
Index templates use site.posts
, but this plugin stores the posts in page.posts
. This is really annoying because in order to re-use templates, I need to do:
{% if page.posts %}
{% assign posts = page.posts %}
{% else %}
{% assign posts = site.posts %}
{% endif %}
{% for post in posts %}
...
{% endfor %}
Unless there is a better way to do it -- but I didn't find one.
Ideally they would both just store it in site.posts
.
I don't know if I understand exactly what you mean but maybe there's a little misunderstanding.
site.posts
(which is provided by jekyll) is an array of all the posts of your jekyll site/blog. page.posts
(on a tag page only!) is an array of all the posts tagged with the specific tag of this page.
I don't think that it would be super smart to overwrite the one with the other.
My particular use case for tags is to generate tag-specific listings and feeds. I also have global listings and feeds. I want to re-use the same template for those two cases.
Am I supposed to do it the way I am right now, with assign? It seems like quite the hack to me.
Am I supposed to do it the way I am right now, with assign? It seems like quite the hack to me.
I would think so. Evaluating a condition to decide behaviour on different circumstances seems legit to me.
{% if post.category not contains 'blog'%}
some actions
{% endif %}
There is any mistake in the code snippet above? The github send me a page build error. I can't fix it. Thanks!
@alexunder I think this is a Jekyll may be Liquid related question and not at all topic of this issue. And to be honest, I don't know. I just didn't work a lot with Jekyll the last two years.