【问题标题】:EJS Header/Footer not displayingEJS页眉/页脚不显示
【发布时间】:2020-11-09 21:41:19
【问题描述】:

我正在使用 EJS 开发一个基本的待办事项列表应用程序。我在跑步时得到这个。我希望能够使用页眉和页脚 EJS 运行 app.js。除了它没有重新调整标题,我确信它是正确的语法。有什么提示或指示可以帮助我吗?

P.S 我所有的 EJS 文件都位于 views 文件夹中

Error: /Users/brenner/dev/web-dev-course/todolist-v1/views/list.ejs:2

Could not find the include file " header"
    1| 
 >> 2| <%- include(" header" ) -%>
    3| 
    4|   <div class="box" id="heading">
    5|     <h1> <%= listTitle %> </h1>

list.ejs:


  <div class="box" id="heading">
    <h1> <%= listTitle %> </h1>
  </div>

  <div class="box">


    <% newListItems.forEach(function(item){ %>
    <form action="/delete" method="post">
      <div class="item">
        <input type="checkbox" name ="checkbox" value="<%=item._id%>" onChange="this.form.submit()">
        <p><%=  newListItems[i].name  %></p>
      </div>
    </form>

    <% }) %>


    <% for (let i=0; i<newListItems.length; i++) { %>
      <div class="item">
        <input type="checkbox">
        <p><%=  newListItems[i].name  %></p>
      </div>
      <input type="hidden" name="listName" value="<%= listTitle %>"></input>
      <% } %>

      <form class="item" action="/" method="post">
        <input type="text" name="newItem" placeholder="New Item" autocomplete="off">
        <button type="submit" name="list" value="<%= listTitle %>">+</button>
      </form>
  </div>

<%- include("footer") -%>

标题


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/styles.css"
  </head>
  <body>

页脚


<footer>
  Copyright 2020 Brenner Inc
</footer>

</html> ```

【问题讨论】:

  • 它说找不到包含文件“header”,所以你有一个名为" header.ejs" 的文件(包括文件名前面的空格)输入)?
  • @Quentin 是的,我的视图文件夹中有一个 header.ejs
  • 文件名以空格开头?真的吗?
  • @Quentin 我什至没有添加空格...保存时的自动格式会这样做
  • 所以修复你的自动格式化程序!

标签: javascript html css layout ejs


【解决方案1】:

试试这个电话&lt;%- include('header') %&gt;。有一个额外空格的错误:( 'header')。应该是('header')

【讨论】:

    猜你喜欢
    • 2013-05-22
    • 2015-03-04
    • 2013-04-08
    • 2023-01-28
    • 2016-06-25
    • 1970-01-01
    • 2017-11-30
    • 2018-07-26
    • 1970-01-01
    相关资源
    最近更新 更多