include - Jekyll/Liquid 动态包含文件

标签 include jekyll liquid

目前我正在使用 Jekyll 开发一个新网站,但遇到了一些问题。我有一个布局页面,我可以在其中使用每个页面的变量定义背景图像。

布局:

class="background background-{{ page.header_bg }}"

页面:

---
header_bg: storm
---

但现在我想根据变量值动态包含一些文件。好吧,我可以用一些 if 或 case 语句来做到这一点,但实际上我想做类似的事情

{% include page.header_bg %}

但这不起作用,因为 Jekyll 正在寻找一个名为“page.header_bg”的文件而不是值。

有人可以帮我吗?

最佳答案

根据to the docs ,您需要将变量名称放入附加 {{ }} 中。

引用链接:

ProTip™: Use variables as file name

The name of the file you wish to embed can be literal (as in the example above), or you can use a variable, using liquid-like variable syntax as in {% include {{my_variable}} %}.

关于include - Jekyll/Liquid 动态包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23541185/

相关文章:

c++ - visual studio 2005 C++ 包含路径

ruby - 输出液体模板中的可用对象和属性

jekyll - 迭代 Markdown 标题以创建导航菜单

ruby-on-rails - 手动安装 Xcode 命令行工具不起作用

shopify - Liquid - 将数组转换为小写

javascript - 这段代码中的 jQuery focus() 方法在做什么?

ruby-on-rails - Rails - 循环不打印液体模板中的数据

c++ - GCC ext headers——最新的文档?

c++ - #error gl.h 包含在 glew.h 之前

c - Visual Studio 引用头文件和源文件