html - 页面属性上的液体过滤数组
问题描述
我有一个 jekyll 站点,它有两个页面(page1.html
和page2.html
),它们都使用相同的布局。此布局打印有关给定子目录中某些其他页面的一些信息。例如
- /_layouts/test.html
{% for p in site.pages %}
{{ p.title }}
{% endfor %}
- /page1.html
---
layout: test
---
this page lists the title of my books...
这将打印我网站中每个页面的标题,但我希望它只打印子目录中页面的标题/books
,所以我会将布局页面更改为
{% for p in site.pages | where: 'dir','/books/' %}
{{ p.title }}
{% endfor %}
这很好用,但我希望另一个页面使用相同的布局并列出我的漫画内容(位于/comics
文件夹内)而不是我的书籍,所以我将通过以下方式更改我的网站的结构:
- /_layouts/test.html
{% for p in site.pages | where: 'dir','/{{ page.directory_to_scan }}/' %}
{{ p.title }}
{% endfor %}
- /page1.html
---
layout: test
directory_to_scan: books
---
this page lists the title of my books...
- /page2.html
---
layout: test
directory_to_scan: comics
---
this page lists the title of my comics...
但是,这不起作用,并且根本没有打印任何标题。
解决方案
您不能混合使用标签和过滤器(除了assign
)。此外,无需将变量括filter
在双括号内:
---
directory_to_scan: '/comics/'
---
布局将使用:
{% assign my_pages = site.pages | where: 'dir', page.directory_to_scan %}
{% for p in my_pages %}
{{ p.title }}
{% endfor %}
推荐阅读
- php - thedevdojo/chatter SQLSTATE[HY000] 外键约束
- floating-point - MIPS:除法算法(IEEE-754 格式的有效位除法)对最后 4-5 位 (LSB) 给出错误答案
- c# - 验证 Web 应用程序中的静态资源
- python - Camelot 只阅读 pdf 的第一页
- php - php 代码没有执行,而只是显示在页面屏幕上
- r - 如何使用 formattable 和 color_tile 有条件地为表格元素着色?
- sql - MS Access SQL 切换功能
- machine-learning - 为什么正态性被认为是因变量和自变量的重要假设?
- java - Spring jpa util 日期
- java - 如何在不等待“completable”完成的情况下与“single”并行执行“completable”?