[英]Controlling whitespace in Pebble templates
I'm having a hard time getting the whitespace control the way that I want in a Pebble template. 我很难在Pebble模板中以所需的方式获取空白控件。 I'm currently generating JSON using Pebble, but this problem and my use case is not specific to JSON (or else I would use a JSON library, such as Jackson instead).
我当前正在使用Pebble生成JSON,但是这个问题和我的用例并不特定于JSON(否则,我将使用JSON库,例如Jackson)。
Here's my Pebble template: 这是我的Pebble模板:
"items": {
{% for item in items -%}
"{{ item.name }}": "{{ item.value }}"{% if not loop.last %},{% endif %}
{% endfor %}
},
And, here's the generated output: 并且,这是生成的输出:
"items": {
"item1": "Value 1",
"item2": "Value 2"
},
There are two problems with this: 这有两个问题:
endfor
and one after the endfor
. endfor
之前,另一个在endfor
。 },
. },
,。 I'd like for the template to look more like the following: 我希望模板看起来更像以下内容:
"items": {
{% for item in items -%}
"{{ item.name }}": "{{ item.value }}"{% if not loop.last %},{% endif %}
{% endfor %}
},
And, I'd like for the resulting output to be: 而且,我希望结果输出为:
"items": {
"item1": "Value 1",
"item2": "Value 2"
},
I have tried many combinations of the whilespace control modifier , but no luck on getting the format that I want. 我已经尝试了whilespace控件修饰符的多种组合,但是在获取所需格式方面并不走运。
Whitespace control modifier only trim lines. 空格控件修改器仅修剪线条。 It doesn't remove line feed.
它不会删除换行符。 The only solution for your use case is to remove blank lines around {% endfor %}
针对您的用例的唯一解决方案是删除{%endfor%}周围的空白行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.