我想要精细控制空白,但仍然有可读模板.
只是想看看其他人的解决方案是通过简单的用例.
{{name}} {{#if age}},{{age}} {{/if}} # outputs {{name}},{{age}} # desire: {{name}},{{age}}
https://github.com/wycats/handlebars.js/issues/479 – 提交了关闭的机票.
解决方法
按照
the pull request to add this feature的历史记录,看起来这是正确的语法:
<h4> {{~#object~}} Surrounding whitespace would be removed. {{/object}} </h4>
结果:
</h4>Surrounding whitespace would be removed.</h4>
还有这种语法只修剪引导空格:
<h4> {{~#object}} Only leading whitespace would be removed. {{/object}} </h4>
结果:
</h4>Only leading whitespace would be removed. </h4>