【问题标题】:nodejs ejs include unexpected identfiernodejs ejs 包含意外的标识符
【发布时间】:2012-12-27 14:57:14
【问题描述】:

我正在使用 nodejs + express + ejs,当我尝试包含另一个视图时遇到问题。

当我尝试时:

<% include dochead %>

我得到“意外的标识符”;
当我尝试时:

<% include /admin/global/dochead %>

我得到'包含未定义';

发生了什么事? 谢谢

【问题讨论】:

  • 感谢您的反对,无论您是谁。
  • 得到同样的东西。不知道
  • @Brig 我还没有找到任何解决方案,我开始使用 Swig 作为模板引擎并且从未回头
  • @user2235057:我从 ejs 切换到 swig。我不能再浪费时间与模板引擎作斗争了。
  • 好的。我已经开始工作了。我收到unexpected identifier 错误,因为我使用的是旧版本的 ejs。切换到最新版本解决了问题。

标签: node.js express ejs


【解决方案1】:

试试

<%- include ('dochead') %>

或

<%- include ('admin/global/dochead') %>

设置

app.set('view engine', 'ejs');
app.set('views', 'YOUR CUSTOM VIEW FOLDER PATH FROM ROOT FILE');

【讨论】:

    【解决方案2】:

    我觉得这里&lt;% include /admin/global/dochead %&gt;应该是

    &lt;% include ../admin/global/dochead %&gt;

    或

    &lt;% include admin/global/dochead %&gt;

    取决于位置。 还要检查您使用的视图引擎

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2015-09-14
      相关资源
      最近更新 更多