2015-08-09 65 views
3

我想在Jekyll的液體模板引擎中做一些基本的算術運算。我已經分配了一個變量numColumns,我試圖在條件語句中使用它。條件語句中的Jekyll算術

{% assign numColumns = 3 %} 

注予省略外側在以下表達式,其中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液體模板引擎?

回答

5

您不能在液體if表達式中使用過濾器。

您必須將assign計算爲一個變量,然後在您的if標記中使用它。

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