简体   繁体   English

Ejs 包含不渲染的部分文件

[英]Ejs include partials files not rendering

I am trying to use ejs in a node.js project.我正在尝试在 node.js 项目中使用 ejs。 I have managed to render the views file(.ejs') and use the.js data in it.我已经设法呈现视图文件(.ejs')并在其中使用.js 数据。 and getting the desired webpage including the stylesheet.并获取包含样式表的所需网页。 the problem occurs only while using partial After importing the header.ejs file in customer.ejs I am getting the exact text syntax of the header.ejs on the webpage.仅在使用部分时出现问题在 customer.ejs 中导入 header.ejs 文件后,我在网页上获得了 header.ejs 的确切文本语法。 <%- include("partials/header") %> In short customer.ejs is locating the header file and importing the it fine. <%- include("partials/header") %>简而言之,customer.ejs 正在定位 header 文件并导入它。 but not rendering it但不渲染它

Output Output

�� <�head> <�link rel="stylesheet" href="/css/style.css"> <�title>Customer<�/title> <�/head> 
Name: abc

my directories are as follows project\public\css\style.scc project\views\partials\header.ejs> project\views\customer.ejs project\app.js i am using Express my syntax are as follows我的目录如下project\public\css\style.scc project\views\partials\header.ejs> project\views\customer.ejs project\app.js我正在使用 Express 我的语法如下

app.js应用程序.js

 app.use(express.static('public'));
 app.set('views', './views');
 app.set('view engine', "views");

customer.ejs客户.ejs

<html >
<%- include("partials/header") %> 
<body>
    <h1>
         Name: <%= customer.name %>
    </h1>   
    
 </body>
 </html>

header.ejs header.ejs

<head>

    <link rel="stylesheet" href="/css/style.css">
    
    <title>Customer</title>
</head>

Things i tried我试过的东西

<%- include partials/header %> <%- include("partials/header") %> <%- include("./partials/header") %> <%- include("partials/header.ejs") %> and several more.. also tried using the express-partial module. <%- include partials/header %> <%- include("partials/header") %> <%- include("./partials/header") %> <%- include("partials/header.ejs") %>和其他几个 .. 也尝试使用express-partial模块。 also tried it on different browsers.也在不同的浏览器上尝试过。 Please let me know if i am doing something wrong or using a decrypted method Any help would be appreciated.如果我做错了什么或使用解密方法,请告诉我任何帮助将不胜感激。 Thank you.谢谢你。

I got the answer to my question after surfing google for a significant amount of time.在谷歌浏览了很长时间后,我得到了问题的答案。 Something went wrong with the Unicode After pasting the following in the root dir the problem was solved. Unicode 出了点问题 将以下内容粘贴到根目录后,问题就解决了。 Just after hitting enter, my entire app.js got changed to some Chinese text.按下回车键后,我的整个 app.js 就变成了一些中文文本。 but ctrl+z brought my code back.但是 ctrl+z 把我的代码带回来了。

Get-Content .\app.js -Encoding Unicode | Set-Content -Encoding UTF8 
.\app-fixed.js ; Move-Item -Path .\app-fixed.js -Destination .\app.js - 
Confirm -Force 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM