我正在使用模板模板语言工具在这里快速找到:https://github.com/stencilproject/Stencil
使用主干道。
问题
给定以下.json文件
{
"xcassets" : "dev Sources test1"
}我希望能够检索由" "分隔的第一个单词,即"dev“。
我试过什么
最新版本的模板具有分裂函数。但问题是,我无法理解如何访问结果数组中的第一个元素,而且它也不在文档中。
我在模具文件中尝试了以下几种方法:
{{xcassets|split:" "[0]}}
{{{{xcassets|split:" "}}[0]}}
{{xcassets|split:" ".first}}
{{xcassets|split:" "}}.first}}
{{xcassets|split:" "|[0]}}
{{xcassets|split:" "|.first}}
{{xcassets|split:" "|first}}都不起作用。
我想要避免
我知道我可以这样做,但一定有更好的办法。
{% for element in xcassets|split:" " %}
{% if forloop.first %}
{{ element }}
{% endif %}
{% endfor %}有人对更好的工具有建议吗?
发布于 2020-09-01 00:57:43
我想这是唯一的办法:
{% for element in xcassets|split:" " %}
{% if forloop.first %}
{{ element }}
{% endif %}
{% endfor %}https://stackoverflow.com/questions/50893399
复制相似问题