我想要对空白进行精细控制,但仍然有可读的模板。
只是想通过简单的用例看看其他人的解决方案。
{{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>
关于whitespace - Handlebars ,空白控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15953293/