首页 > 解决方案 > 面临与在节点中添加页眉和页脚相关的错误

问题描述

我正在尝试将页眉和页脚 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)

在此处输入图像描述

标签: node.jsejs

解决方案


语法变了

<%- include('partials/header') %>
<%- include("partials/footer") %>

我猜你正在使用ejs

app.set("view engine", "ejs");

有关更多信息,请参阅 ejs 文档


推荐阅读