[英]Ejs include partials files not rendering
我正在尝试在 node.js 项目中使用 ejs。 我已经设法呈现视图文件(.ejs')并在其中使用.js 数据。 并获取包含样式表的所需网页。 仅在使用部分时出现问题在 customer.ejs 中导入 header.ejs 文件后,我在网页上获得了 header.ejs 的确切文本语法。 <%- include("partials/header") %>
简而言之,customer.ejs 正在定位 header 文件并导入它。 但不渲染它
Output
�� <�head> <�link rel="stylesheet" href="/css/style.css"> <�title>Customer<�/title> <�/head>
Name: abc
我的目录如下project\public\css\style.scc
project\views\partials\header.ejs>
project\views\customer.ejs
project\app.js
我正在使用 Express 我的语法如下
应用程序.js
app.use(express.static('public'));
app.set('views', './views');
app.set('view engine', "views");
客户.ejs
<html >
<%- include("partials/header") %>
<body>
<h1>
Name: <%= customer.name %>
</h1>
</body>
</html>
header.ejs
<head>
<link rel="stylesheet" href="/css/style.css">
<title>Customer</title>
</head>
我试过的东西
<%- include partials/header %>
<%- include("partials/header") %>
<%- include("./partials/header") %>
<%- include("partials/header.ejs") %>
和其他几个 .. 也尝试使用express-partial
模块。 也在不同的浏览器上尝试过。 如果我做错了什么或使用解密方法,请告诉我任何帮助将不胜感激。 谢谢你。
在谷歌浏览了很长时间后,我得到了问题的答案。 Unicode 出了点问题 将以下内容粘贴到根目录后,问题就解决了。 按下回车键后,我的整个 app.js 就变成了一些中文文本。 但是 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.