我在 jinja2模板中有一些变量,它们是由“ ;”分隔的字符串。
我需要在代码中分别使用这些字符串。 也就是说,变量是 variable1 = “绿色; 蓝色”
{% list1 = {{ variable1 }}.split(';') %}
The grass is {{ list1[0] }} and the boat is {{ list1[1] }}
I can split them up before rendering the template but since it are sometimes up to 10 strings inside the string this gets messy.
之前我有一个 jsp:
<% String[] list1 = val.get("variable1").split(";");%>
The grass is <%= list1[0] %> and the boat is <%= list1[1] %>
编辑:
它的工作原理是:
{% set list1 = variable1.split(';') %}
The grass is {{ list1[0] }} and the boat is {{ list1[1] }}