Jekyll site.categories.{{variable}}?

拈花ヽ惹草 提交于 2019-12-05 15:23:15

问题


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.*


回答1:


The correct syntax for the loop is

{% for post in site.categories[cat] %}



回答2:


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!



来源:https://stackoverflow.com/questions/22441281/jekyll-site-categories-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!