node.js - 面临与在节点中添加页眉和页脚相关的错误
问题描述
我正在尝试将页眉和页脚 ejs 文件添加到我的 /views ejs 模板中,但它显示错误 ReferenceError: E:\Web Dev\Hill Station\views\add.ejs:1
<% include /partials/header %>
<h2>Hey,Ready to add a new and cool refreshmemt Hill Station</h2>
partials is not defined
at eval (eval at compile (E:\Web Dev\Hill Station\node_modules\ejs\lib\ejs.js:661:12), <anonymous>:8:17)
at add (E:\Web Dev\Hill Station\node_modules\ejs\lib\ejs.js:691:17)
at tryHandleCache (E:\Web Dev\Hill Station\node_modules\ejs\lib\ejs.js:272:36)
at View.exports.renderFile [as engine] (E:\Web Dev\Hill Station\node_modules\ejs\lib\ejs.js:489:10)
at View.render (E:\Web Dev\Hill Station\node_modules\express\lib\view.js:135:8)
at tryRender (E:\Web Dev\Hill Station\node_modules\express\lib\application.js:640:10)
at Function.render (E:\Web Dev\Hill Station\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (E:\Web Dev\Hill Station\node_modules\express\lib\response.js:1012:7)
at E:\Web Dev\Hill Station\hillstation.js:18:9
at Layer.handle [as handle_request] (E:\Web Dev\Hill Station\node_modules\express\lib\router\layer.js:95:5)
解决方案
语法变了
<%- include('partials/header') %>
<%- include("partials/footer") %>
我猜你正在使用ejs
app.set("view engine", "ejs");
有关更多信息,请参阅 ejs 文档
推荐阅读
- android - 如何解决flutter.gradle和flutter.bat报错?flutter2.5
- docker - 为 vpn 创建 docker 网络
- django - Django服务器没有启动
- firebase - 当 Firebase 连接到后端时,如何上传到前端的 Firebase 存储?
- javascript - Cypress 捕捉小吃店
- flutter - 为什么依赖项覆盖在颤振中不能按预期工作?
- github-pages - Github Actions 克隆无法读取用户名
- javascript - 如何过滤作为对象数组中对象属性的电子邮件域?
- swiftui - TabView 中的 SwiftUI 导航标题
- python - 谁能推荐如何解决这个错误?