Jack
Jack

Reputation: 491

"SyntaxError: Unexpected token '/' ... while compiling ejs" happening in include statement

I cant seem to find why this is happening, I have pretty much the same code across most of my apps, its pretty much the boiler plate, im just trying to separate the top of the HTML into a header.ejs and the bottom into a footer.ejs file and then include them into my index.ejs. When i keep all the code in the index.ejs file its fine. Ive also tried removing the spaces like so <%include ./partials/header.ejs%>, adding the '-' <%- include ./partials/header.ejs %>, I still get this error even though I have the same code - same syntax across my files.

Index.ejs

<% include ./partials/header.ejs %>

<h1>YO HO HO LET THIS WORK!</h1>

<% include ./partials/footer.ejs %>

Header.ejs

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>P2</title>
    <link rel="stylesheet" href="/stylesheets/app.css">
</head>
<body>

Footer.ejs

</body>
</html>

Upvotes: 0

Views: 1502

Answers (3)

BotJS
BotJS

Reputation: 1

Hi i found a solution that works for me here is the syntax to use.

 "dependencies": {
    "ejs": "^3.0.1",
 }"

<%- include('../pages/header.ejs') %>

    <h1>Hi ejs </h1>
<%- include('../pages/footer.ejs') %>

Folder: -pages: -header.ejs -footer.ejs

Upvotes: 0

Neil Cooper
Neil Cooper

Reputation: 102

which version of ejs are you using?

i noticed that the recent version bump from 2.7.4. to 3.0.1 meant that includes need to look more like:

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

<h1>YO HO HO LET THIS WORK!</h1>

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

Upvotes: 6

Lofn
Lofn

Reputation: 940

Try using this for index.ejs

<%=include partials/header.ejs%>

<h1>YO HO HO LET THIS WORK!</h1>

<%=include partials/footer.ejs%>

Upvotes: -1

Related Questions