最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do you prevent newline added to Handlebars partial? - Stack Overflow

programmeradmin2浏览0评论

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 es across with the newline. There's no newline in the file.

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 es across with the newline. There's no newline in the file.

Share Improve this question asked Jun 19, 2014 at 22:52 Ain TohvriAin Tohvri 3,0356 gold badges34 silver badges51 bronze badges 2
  • 1 Are you prepiling ur templates? Maybe BOM character is getting added. – blessanm86 Commented Jun 20, 2014 at 7:12
  • Checked against it, used :set nobomb and resaved (in Vim), still the same. – Ain Tohvri Commented Jun 20, 2014 at 9:13
Add a ment  | 

2 Answers 2

Reset to default 5

It's on the handlebarsjs., 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)

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

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

au BufWritePre * :set binary | set noeol
au BufWritePost * :set nobinary | set eol
发布评论

评论列表(0)

  1. 暂无评论