ejs-mate 包中未定义布局

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

错误

样板

我不知道为什么布局没有定义我已经安装了 ejs-mate 和 ejs 并且仍然这样说


<% layout('layouts/boilerplate') %>

<h1>All campgrounds </h1>
<div>
    <a href="/campgrounds/new">Add New Campground</a>
</div>
<ul>

    <% for(let campground of campgrounds ){%>

            <li><a href = "/campgrounds/<%=campground._id%>"><%=campground.title%></a></li>
    <%}%>
</ul>

文件

javascript html node.js ejs
5个回答
2
投票

可能需要检查app.js 文件。当我省略“;”时,我收到此错误之后: const ejsMate = require('ejs-mate').

还要仔细检查您的 app.engine('ejs', ejsMate)


1
投票

此问题来自您的 app.js 文件。 确保您已定义 ejs-package 并指定引擎,如下所示:

const engine = require('ejs-mate');
app.engine('ejs', engine);


0
投票

你应该使用

include
代替
layout
,如下所示:-

  <%- include('../layouts/boilerplate'); %>

有关更多信息,请检查此链接:- https://www.digitalocean.com/community/tutorials/how-to-use-ejs-to-template-your-node-application 或者告诉我


0
投票

尝试检查你的app.js文件是否写了这个:

app.engine('ejs', ejsMate);

我有同样的错误,因为我使用了

app.use
而不是
app.engine


0
投票

目前您正在使用

<% layout('layouts/boilerplate') %>

但是你应该使用

<%- layout('layouts/boilerplate') %>

您错过了

-
之后的
<%

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