1

I've set up an EJS partial under a path views/partials/ejspartial.ejs which I am trying to access in an ejs file with the path views/ejsfile.ejs. This is the same views directory.

In the ejsfile.ejs, I've added the following line of code: <% include ./partials/ejspartial %>

When I load the ejsfile page, I get the following error:

SyntaxError: Unexpected token '/' in <path>/views/ejsfile while compiling ejs

I've tried swapping in the <%- tag and removing the ./ from the include statement, but the same error occurs.

4
  • the include is correct, its something else. post the contents of <path>/views/ejsfile.ejs or look for some odd / Commented Dec 5, 2019 at 20:14
  • I placed the contents of the partial directly into the ejsfile replacing the include portion. It works as intended. I'm just trying to reference it in the ejs partial instead of directly into the view. Commented Dec 5, 2019 at 20:24
  • Can you post views/ejsfile.ejs? Commented Dec 5, 2019 at 23:09
  • Try <%- include('partials/ejspartial') %> Commented Dec 5, 2019 at 23:13

1 Answer 1

1

I suspect it is because you are using the syntax of an older version of EJS.

I notice that the docs say: "NOTE: Include preprocessor directives (<% include user/show %>) are still supported."

However, the owner of the EJS repository says otherwise here: https://github.com/tj/ejs/issues/220

I would try the new syntax, <%- include('partials/ejspartial') %>, and see if that solves the issue.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked. I was missing the single quotes inside of the parenthesis. Thank you!!
Awesome! Can you accept my answer as correct for people facing a similar issue then?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.