EJS意外令牌/-使用部分

问题描述 投票:0回答:1

我正在尝试在Web应用程序中使用局部函数,但是在仪表板页面上,出现以下错误:

SyntaxError: Unexpected token / in /Users/ng235/Documents/Work/app-1/views/dashboard.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://Work.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
    at new Function (<anonymous>)
    at Template.compile (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:626:12)
    at Object.compile (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:366:16)
    at handleCache (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:215:18)
    at tryHandleCache (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:254:16)
    at View.exports.renderFile [as engine] (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:459:10)
    at View.render (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/view.js:135:8)
    at tryRender (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/application.js:640:10)
    at Function.render (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/response.js:1012:7)
    at /Users/ng235/Documents/Work/app-1/app.js:51:9
    at Layer.handle [as handle_request] (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/layer.js:95:5)
    at /Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/index.js:281:22

我包含我的部分内容的方式是:

<% include ./partials/messages %>

我的文件系统是app-2->视图->局部-> messages.ejs

该文件为:

<% if (message && message.length > 0) { %>
<div class="alert alert-primary my-5"><%= message %></div>
<% } %>

我的仪表板页面(我试图向其中添加部分页面的页面是(不试图泄漏任何东西):]

<div class="container text-center">
    <h1 class="display-4 my-5">Dashboard</h1>

    <% include ./partials/messages %>
</div>

感谢您的所有帮助。

node.js ejs partials
1个回答
0
投票

EJS现在对从版本3.x.x开始的部分使用不同的语法

<%- include ./partials/file %>替换<% include ./partials/file %><%- include('./partials/file') %>

新语法是:<%- include('./partials/file') %>

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.