testplugin.testplugin.firstkey具有以下值1、2、3
我有用树枝写的代码:
{% set key1 = [config("testplugin.testplugin.firstkey")] %}
{% for ids in key1 %}
{% set key1 = ids %}
GO-{{ ids }} {% if not loop.last %},{% endif %}
{% endfor %}问题是,config("testplugin.testplugin.firstkey")不会被正确地解析。实际上,它只被解析为一个值,而不是数组中的3个分隔值。但是,当我手动定义值时--没有变量--它的工作原理是:
{% set key2 = [1, 2, 3] %}
{% for ids in key2 %}
{% set key2 = ids %}
GO-{{ ids }} {% if not loop.last %},{% endif %}
{% endfor %}第一个代码是这样做的:
GO-1, 2, 3第二个是这样的(它应该是这样的):
GO-1, GO-2, GO-3所以我的问题是,为什么doeas第一段代码不能正常工作?
发布于 2020-03-25 23:53:42
我可以自己想办法:
{% set key1 = config("testplugin.testplugin.firstkey"))|split(',') %}
{% for ids in key1 %}
{% set key1 = ids %}
GO-{{ ids }} {% if not loop.last %},{% endif %}
{% endfor %}无论如何,谢谢;-)
https://stackoverflow.com/questions/60858961
复制相似问题