条件语句中的 Jekyll 算术

标签 jekyll liquid

我试图在 Jekyll 的液体模板引擎中做一些基本的算术。我已经分配了一个变量 numColumns我试图在条件语句中使用它。

{% assign numColumns = 3 %}

注意我在下面的表达式中省略了外部 for 循环,其中 loopindex来自。无论如何,这适用于 -运算符并正确计算为 2。
{% if loopindex == 3 - 1 %}

但是,我尝试过的这些替代方法不起作用:
{% if loopindex == numColumns - 1 %}
{% if loopindex == numColumns | minus: 1 %}
{% if loopindex == {{ numColumns }} - 1 %}
{% if loopindex == {{ numColumns | minus: 1 }} %}

如何从 numColumns 中减去一在液体模板引擎的条件语句中?

最佳答案

您不能在液体中使用过滤器 if表达。

你必须assign您对变量的计算,然后在您的 if 中使用它标签。

{% assign calc = numColumns | minus: 1 %}
{% if loopindex == calc %}

关于条件语句中的 Jekyll 算术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31901315/

相关文章:

jekyll - 如何使用 Liquid 列出目录中的文件?

ruby - Hpricot 版本无法正常工作

jekyll - 为什么 Jekyll's Liquid 'contains' 返回一个字符串?

jekyll - Liquid 中有没有办法使用 contains 运算符来检查精确匹配?

yaml - 从 Jekyll 数据文件中的 yaml 多行字符串渲染 Markdown

blockchain - 一个流动性池可以有2个以上的代币吗

ruby - jekyll 服务依赖错误 - 无法打开 'lib curl'

gruntjs - 咕噜声 : watch command never runs when including other tasks in registerTask method

jekyll - 在 Jekylls Front Matter 中使用变量

ruby - Ruby 的 Liquid 模板引擎中的模数(或缺少模数)