I want to make an archive page with the example generator from the Jekyll documentation. The generator works fine but I don't know to implement the layout correctly. I am using the following file so far:
{% assign cat = page.category %}
<div class="category-archive">
<div>
<span class="title">Category archive for {{ cat }}</span>
</div>
<div>
{{ cat }}
<ul class="posts">
{% for post in site.categories.cat %}
<li><span>{{ post.date | date_to_string }} - </span> <a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
</div>
</div>
How can I use the current category from page.category
like with a variable I am trying to use here?
TL;DR
I want to use a liquid variable at site.categories.*
I figured it out myself!
The line{% for post in site.categories.cat %}
can be written like:{% for post in site.categories.[page.category] %}
It didn't know about the use of these brackets!
The correct syntax for the loop is
{% for post in site.categories[cat] %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With