[英]How to create an array in a for loop in Liquid?
我正在尝试使用 Liquid 语法从对象列表创建一个数组:
{% for operation in menuItems %}
{% assign words1 = operation.Title | split: '_' %}
{% assign controllerName = words1 | first %}
{% assign controllersTmp = controllersTmp | append: '_' | append: controllerName %}
{% endfor %}
我想拆分controllersTmp
以获得我的数组,但此时我的controllersTmp
为空。
有什么帮助吗?
您可以直接创建一个新的空数组controllers
和concat
它你controllerName
转换成使用解决方法数组split:''
。 结果直接是一个数组,没有额外的字符串操作。
{% assign controllers = '' | split: '' %}
{% for operation in menuItems %}
{% assign controllerName = operation.Title | split: '_' | first | split: '' %}
{% assign controllers = controllers | concat: controllerName %}
{% endfor %}
什么对我有用
{% assign otherarticles = "" | split: ',' %}
{% assign software_engineering = "" | split: ',' %}
{% for file in site.static_files %}
{% if file.extname == ".html" %}
{% if file.path contains "software_engineering" %}
{% assign software_engineering = software_engineering | push: file %}
{% else %}
{% assign otherarticles = otherarticles | push: file %}
{% endif %}
{% endif %}
{% endfor %}
你必须初始化你的变量 controllersTmp :
{% assign controllersTmp = '' %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.