Ejs 包含不渲染的部分文件
Ejs include partials files not rendering
我正在尝试在节点 js 项目中使用 ejs。
我已经设法呈现视图文件 (.ejs') 并在其中使用 .js 数据。
并获取包含样式表的所需网页。
仅在使用部分时出现问题
在 customer.ejs 中导入 header.ejs 文件后,我得到了网页上 header.ejs 的确切文本语法。
<%- include("partials/header") %>
简而言之,customer.ejs 正在定位头文件并导入它。但不渲染它
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
我正在使用快递
我的语法如下
app.js
app.use(express.static('public'));
app.set('views', './views');
app.set('view engine', "views");
customer.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>
Things i tried
<%- include partials/header %>
<%- include("partials/header") %>
<%- include("./partials/header") %>
<%- include("partials/header.ejs") %>
还有几个..
还尝试使用 express-partial
模块。
也在不同的浏览器上尝试过。
如果我做错了什么或使用解密方法,请告诉我
任何帮助,将不胜感激。
谢谢。
我在浏览 google 很长一段时间后得到了问题的答案。
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
我正在尝试在节点 js 项目中使用 ejs。
我已经设法呈现视图文件 (.ejs') 并在其中使用 .js 数据。
并获取包含样式表的所需网页。
仅在使用部分时出现问题
在 customer.ejs 中导入 header.ejs 文件后,我得到了网页上 header.ejs 的确切文本语法。
<%- include("partials/header") %>
简而言之,customer.ejs 正在定位头文件并导入它。但不渲染它
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
我正在使用快递
我的语法如下
app.js
app.use(express.static('public'));
app.set('views', './views');
app.set('view engine', "views");
customer.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>
Things i tried
<%- include partials/header %>
<%- include("partials/header") %>
<%- include("./partials/header") %>
<%- include("partials/header.ejs") %>
还有几个..
还尝试使用 express-partial
模块。
也在不同的浏览器上尝试过。
如果我做错了什么或使用解密方法,请告诉我
任何帮助,将不胜感激。
谢谢。
我在浏览 google 很长一段时间后得到了问题的答案。 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