使用EJS添加部分模板时的空白 [英] whitespaces when adding partial template using EJS
问题描述
当我使用<%include partials / template.ejs%> 添加部分内容时,在布局文件中的<%partial('partials / template.ejs')中,我在编译的HTML代码(template.ejs)之前获得空格。
请注意,当我将template.ejs内容复制粘贴到布局中(不使用include / partials)时,空格将消失。
请参见下图: / p>
第一部分:代码。
第二部分: chrome DOM。
第3部分:空格元素检查(DOM属性)
我遇到同样的事情,至少在我的情况下,这是由于EJS部分功能使用
fs.readFileSync(file,'utf8')
根据
https://github.com/nodejs/node-v0.x-archive/issues/1918
不会删除UTF-8 BOM。尽管如果EJS引擎为我们剥离了BOM,那么如果没有BOM将部分文件保存在UTF-8中,解决了我的问题。
I am using SailsJS with EJS engine.
When I add partials using <% include partials/template.ejs %> or <% partial('partials/template.ejs') in the layout file, I get whitespaces before the compiled HTML code (template.ejs).
Note that when I copy paste the template.ejs content in the layout (not using include/partials) the whitespaces are gone.
See images below:
1st part: code.
2nd part: chrome DOM.
3rd part: whitespace element inspection (DOM properties)
I encountered the same thing and at least in my case this was due to the EJS partial function using
fs.readFileSync(file, 'utf8')
which according to
https://github.com/nodejs/node-v0.x-archive/issues/1918
does not remove the UTF-8 BOM. While it would be nice if the EJS engine stripped away the BOM for us, saving the partial files in UTF-8 without the BOM solved my problem.
这篇关于使用EJS添加部分模板时的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!