我正在尝试使用 Liquid 语法从对象列表创建一个数组:
{% for operation in menuItems %}
{% assign words1 = operation.Title | split: '_' %}
{% assign controllerName = words1 | first %}
{% assign controllersTmp = controllersTmp | append: '_' | append: controllerName %}
{% endfor %}
我想分割controllersTmp
得到我的数组,但此时我的controllersTmp
是空的。
有什么帮助吗?
可以直接新建一个空数组controllers
and concat https://help.shopify.com/themes/liquid/filters/array-filters#concat给它你的controllerName
使用解决方法转换为数组split:'' https://help.shopify.com/themes/liquid/filters/string-filters#split。结果直接是一个数组,没有额外的字符串操作。
{% assign controllers = '' | split: '' %}
{% for operation in menuItems %}
{% assign controllerName = operation.Title | split: '_' | first | split: '' %}
{% assign controllers = controllers | concat: controllerName %}
{% endfor %}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)