EJS not able to render page due to class declaration

276 Views Asked by At
<header class="main-header">
<nav class="main-header__nav">
    <ul class="main-header__item-list">
        <li class="main-header__item"><a class="<%= path === '/' ? 'active' : '' %>" href="/">Shop</a></li>
        <li class="main-header__item"><a class="<%= path === '/admin/add-product' ? 'active' : '' %>" href="/admin/add-product">Add Product</a></li>
    </ul>
</nav>

When I try to render the page in my node js application I am getting an error. Saying there is an error

I am not so used to writing ejs but when I remove the class="<%= path === '/' ? 'active' : '' %>" in the navigation.ejs it seems to work

enter image description here

Error Image

1

There are 1 best solutions below

2
On

Use <%- include('RELATIVE/PATH/TO/FILE'); %> to embed an EJS partial in another file.

  • The hyphen <%- instead of just <% tells EJS to render raw HTML.
  • The path to the partial is relative to the current file.
  • and also use ; at end of include

Here is an example...

<!DOCTYPE html>
<html lang="en">
<head>
    <%- include('../partials/head'); %>
</head>
<body class="container">

<header>
    <%- include('../partials/header'); %>
</header>

<main>
    <div class="jumbotron">
        <h1>This is great</h1>
        <p>Welcome to templating using EJS</p>
    </div>
</main>

<footer>
    <%- include('../partials/footer'); %>
</footer>

</body>
</html>