好吧,我有一个主要是静态的主页,但我希望有部分视图,用于导航,页脚等.我正在使用ejs,它看起来像这样:
我的控制器:home.js
// Dependencies
var express = require('express');
module.exports = {
get: function(req, res) {
app.set('view engine', 'ejs');
var model = {
layout:'home',
};
res.render('home');
}
};
Run Code Online (Sandbox Code Playgroud)
我的views目录有nav,home和footer all .ejs
然后剥离文本的实际html文件看起来如下.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" >
<title>Tom Jones</title>
<!-- CSS -->
<link rel="stylesheet" href="/css/home.css" type="text/css" media="screen" >
</head>
<body>
<%- partial('nav') %>
<!--content part -->
<div id="showcontainer">
<section>
</section>
</div>
<div id="maincontainer">
<section>
</section>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
问题当我测试它时,我遇到错误部分未定义.我试过要求ejs但没有成功.
我的 ejs 文件路径不起作用。
SyntaxError: Unexpected token '/' in C:\Users\mikda\Desktop\ColtFULL\Section33\YelpCamp\v3\views\landing.ejs 编译 ejs 时
如果上述错误没有帮助,您可能想尝试 EJS-Lint:https : //github.com/RyanZim/EJS-Lint或者,如果您打算创建一个异步函数,请通过
async: true作为一种选择。在新函数 () at Template.compile (C:\Users\mikda\Desktop\ColtFULL\Section33\YelpCamp\v3\node_modules\ejs\lib\ejs.js:626:12) 在 Object.compile (C:\Users \mikda\Desktop\ColtFULL\Section33\YelpCamp\v3\node_modules\ejs\lib\ejs.js:366:16) 在 handleCache (C:\Users\mikda\Desktop\ColtFULL\Section33\YelpCamp\v3\node_modules\ejs \lib\ejs.js:215:18) 在 tryHandleCache (C:\Users\mikda\Desktop\ColtFULL\Section33\YelpCamp\v3\node_modules\ejs\lib\ejs.js:254:16) 在 View.exports。 renderFile [作为引擎] (C:\Users\mikda\Desktop\ColtFULL\Section33\YelpCamp\v3\node_modules\ejs\lib\ejs.js:459:10) 在 View.render (C:\Users\mikda\Desktop \ColtFULL\Section33\YelpCamp\v3\node_modules\express\lib\view.js:135:8) 在 tryRender (C:
这是我的代码
请在此 输入图片说明 请在此输入图片说明 请在此处 输入图片说明
在此处输入图片描述 有人可以解决这个问题吗?