Node handlebars adds extra text node before rendered view

有些话、适合烂在心里 提交于 2019-12-07 16:52:14

问题


I have the following issue: When rendering a view in a layout with handlebars, the engine adds an extra text node before the rendered view body

<nav></nav>
{{{body}}}
<footer></footer>

results in

<nav></nav>
"
[empty text node here]
                      "
<rendered view>
<footer></footer>

That empty text node has its own height and breaks my CSS margins and paddings. Note that if I put the view HTML directly in the layout without using handlebars templating, there is no text node and everything is fine.

Any ideas why is this happening and how to solve it?


回答1:


I think I found the reason, please check your partial view file, whether there is BOM inserted in file, some editors will insert this in file with UTF-8, UTF-16 and UTF-32 format. so if you are using UTF-8, just remove the BOM will be good.




回答2:


@leoyoo answer is the right one. I was about to post same question and found this.

On Chrome, source shows that white space character as seen below (red dot):

...and stringifies to &#65279;

I'm on Visual Studio and this is the default setting when files are saved:

When I change it to UTF-8 without signature (as seen below) that whitespace character dissapears.

On Visual Studio you do: File>>Save fileName.ext As and then drop-down next to Save button.



来源:https://stackoverflow.com/questions/27534473/node-handlebars-adds-extra-text-node-before-rendered-view

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