How do you prevent newline added to Handlebars partial?

偶尔善良 提交于 2019-12-10 20:51:06

问题


Scenario: one-line Handlebars partial used in an inline element:

Handlebars template:

<a href="#section">{{> partial}}Label</a>

Partial:

<svg class="icon" viewBox="0 0 65 65"><use xlink:href="#icon"></use></svg>

Compilation result:

<a href="#section"><svg class="icon" viewBox="0 0 65 65"><use xlink:href="#icon"></use></svg>
Label</a>

As you see, partial comes across with the newline. There's no newline in the file.


回答1:


It's on the handlebarsjs.com, but not documented well enough (for me);

after a half an hour of struggling wandering where exactly am I supposed to set this "~"

{{#each arrayOfItems ~}}
<div>
{{~> item ~}}
</div>
{{~each}}

aaand, works like a charm for me:)

(handlebars-express3 on Node.js)




回答2:


The issue was caused by the Vim's EOL management.

To prevent newline appearing after the Handlebars compilation, change Vim configuration (.vimrc) to include:

au BufWritePre * :set binary | set noeol
au BufWritePost * :set nobinary | set eol


来源:https://stackoverflow.com/questions/24317474/how-do-you-prevent-newline-added-to-handlebars-partial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!