Nguyen Hoang Vu
Nguyen Hoang Vu

Reputation: 853

Include partial with ejs

I'm trying to include a menu in my page with this code:

<%- include ../common/menu %>

Here is the file directory: /views/common/menu.ejs

Here is my menu.ejs:

<div class="button" id="menu-btn">
    <a class="btn-open" href="#"></a>
  </div>
  <div class="overlay">
    <div class="wrap">
      <ul class="wrap-nav">
        <li>
          <a href="/">Welcome Page</a>
          <ul>
            <li>
              <a href="/main">Main Page</a>
            </li>
            <li>
              <a href="/vungtau">Vũng Tàu</a>
            </li>
            <li>
              <a href="/suoimo">Đồng Nai - Suối Mơ</a>
            </li>
            <li>
              <a href="/dalat">Đà Lạt</a>
            </li>
            <li>
              <a href="/video">Video</a>
            </li>
          </ul>
      </ul>
    </div>
  </div>

I got a 500 Internal Server Error but I did not know why? I'm following this tutorial: https://scotch.io/tutorials/use-ejs-to-template-your-node-application

I did many search on google but it s no help.

Upvotes: 1

Views: 4506

Answers (3)

lawrghita
lawrghita

Reputation: 29

If I use this folder structure:

../views/partials/header.ejs
../views/partials/footer.ejs
../views/users.ejs

then in users.ejs:

<%- include('./partials/header.ejs') %>
<body>
...
</body>
<%- include("./partials/footer.ejs") %>

Upvotes: 2

Prathamesh More
Prathamesh More

Reputation: 1489

Try to use this new syntax

<%- include("partials/header") %>
<%- include("partials/footer") %>

Upvotes: 1

Kevin T.
Kevin T.

Reputation: 758

try this

<%- include('../common/menu.ejs') %>

docs http://ejs.co/#docs

Upvotes: 4

Related Questions