0

我在 lektor 的第一次尝试:我想为建筑作品记录创建自己的数据模型。我有一个奇怪的输出checkboxeslists比如:

    [u'corporate & commercial', u'interiors']

poject.ini在哪里

[fields.type]
label = Project type
type = checkboxes
choices = corporate & commercial, residential, interiors, public,hotel/tourism, university, art gallery, restoration, spa, auditorium,  installations, landscape
choice_labels = corporate & commercial, residential, interiors, public, hotel/tourism, university, art gallery, restoration, spa, auditorium,  installations, landscape

并且project.html有:

{% if this.type %}
<tr>
<th scope="row">Type</th>
<td>{{ this.type}}</td>
</tr>
{% endif %} 

输出中的那些[u'来自哪里?我错过了什么?

谢谢

AR(在 win 7/64 上运行 lektor 3.0.1)

4

2 回答 2

0

当您调用 时{{ this.type }},您将获得整个数组的完整原始结果。

查看您的示例页面后,您的目标似乎是将每个项目单独称为列表。为此,您需要遍历数组:

{% for item in this.type %}{{ item }}{% if not loop.last %}, {% endif %}{% endfor %}

这应该输出为“第 1 项,第 2 项,第 3 项”。如果要更改分隔符,请编辑 和 之间的{% if not loop.last %}{% endif %}

于 2019-06-29T17:47:09.077 回答
0

表示一个列表([u或数组)。this.type是您的选择列表,要获得一个项目,您可以使用 for 循环或过滤器等。

于 2018-02-09T12:44:52.960 回答