Jekyll –检查页面是否属于集合 [英] Jekyll – Check if page belongs to a collection

查看:71
本文介绍了Jekyll –检查页面是否属于集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查当前页面是否属于某个集合?如果是这样,我可以检查收藏的标签是什么吗?

Is there a way to check if a current page belongs to a collection? If so, can I check what’s the label of the collection?

背景故事: 我想要达到的目的是为属于集合的所有页面显示不同的布局.使用这种新布局,我想显示一个侧面导航(某种形式的另请参阅"),其中列出了当前站点所属集合中的所有页面.

Background story: What I’m trying to achieve is to display a different layout for all pages that belong to a collection. With this new layout I want to display a side navigation (some sort of „See also") with listing of all pages in the collection that the current site belongs to.

如果我的问题变得愚蠢–请原谅,我是jekyll的新手,我真的想自己找出答案.

In case my question turns out to be dumb – forgive me, I’m new to jekyll and I really tried to find out the answer by myself.

推荐答案

page.collection返回文档所属集合的标签.所以我想你想做类似的事情:

page.collection returns the label of the collection to which the document belongs. So I guess you want to do something like:

{% if page.collection == 'COLLECTION_LABEL' %}
NEW LAYOUT
{% else %}
OLD LAYOUT
{% endif %}

要访问集合中的页面,可以将标签与site.COLLECTION_LABELsite[COLLECTION_LABEL]一起使用(如果它是变量,则需要[]).像这样:

To access the pages in a collection, you can use the label with site.COLLECTION_LABEL or site[COLLECTION_LABEL] (you need [] if it is a variable). Something like:

{% for page in site[page.collection] %}
<a href="{{ page.url }}">{{ page.title }}</a>
{% endfor %}

这篇关于Jekyll –检查页面是否属于集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆