2016-11-11 43 views
0

我遇到了一个简单无聊的错误。根据循环添加一定量的字符集值的任务。但是,段语法上的流体拒绝这样做。标志的比较在液体语法中不起作用

{% assign text = 'Some example text here' %} // Variable here 
 
{% unless text.size < 100 %}     // Start loop 
 
    {% assign text = text | append: '#' %} // Concate and iterate at the same time 
 
{% endunless %}        // End loop 
 
         
 
{{text}}          // Output value to screen

其结果是我希望看到这样的事情:这里的一些示例文本###################### ################################################## #######

请帮忙!

回答

1

你不能做一个循环除非,除非只发生一次。

{% assign text = 'Some example text here' %} 

{% for i in (1..100) -%} 
    {% if i == text.size -%} 
     {% break %} 
    {% else -%} 
     {% assign text = text | append: '#' %} 
    {% endif -%} 
{% endfor -%} 
{{text}} 
+0

你可以在这里找到很多有用的信息http://docs.businesscatalyst.com/cheat#liquid – Daut

+0

哦不错,我来试试,现在... – user3688243

+0

它的工作原理!我很开心! – user3688243