使用变量作为 Liquid 中极限表达式的值
Use a Variable as the Value for a Limit Expression in Liquid
我正在为 Jekyll 编写一个 Liquid 模板,并希望这样做:
{% for example in examples | limit:{{ site.examplelimit}} %}
然而,这永远行不通。 {{ site.examplelimit}}
returns 一个值,甚至更精确的值,例如在上面的前面加上:
{% capture examplelimitint %}site.examplelimit{% endcapture %}
{% assign examplelimitint = examplelimitint | plus:0 %}
...没有帮助。
那么,Liquid中真的没有办法用变量来限制数值吗?
你可以试试:
{% for example in examples | limit: site.examplelimit %}
我正在为 Jekyll 编写一个 Liquid 模板,并希望这样做:
{% for example in examples | limit:{{ site.examplelimit}} %}
然而,这永远行不通。 {{ site.examplelimit}}
returns 一个值,甚至更精确的值,例如在上面的前面加上:
{% capture examplelimitint %}site.examplelimit{% endcapture %}
{% assign examplelimitint = examplelimitint | plus:0 %}
...没有帮助。
那么,Liquid中真的没有办法用变量来限制数值吗?
你可以试试:
{% for example in examples | limit: site.examplelimit %}