vardha
vardha

Reputation: 414

pass an object inside ejs include statement

I need to pass an object inside an ejs include statement. I found a couple of questions on the same issue but I get a weird error when i do the following,

<div>
<%- include (folder/index , {"user": user}) %>
</div>

I get,

ENOENT: no such file or directory, open '/views/(folder/index.ejs'

Any idea why i get a enoent when i pass the object inline ?

if i simply do,

<%- include folder/index %>

this works

but i need to pass user object to index. is there a way to do this?

Upvotes: 2

Views: 1130

Answers (2)

XEmporea
XEmporea

Reputation: 35

found a solution... Yes. I missed the obvious.

var json_tmp = JSON.parse('<%- JSON.stringify(pass_object) %>');

Upvotes: 0

dNitro
dNitro

Reputation: 5355

When you insert space after include, EJS will use include preprocessor directives (<% include folder/index %>); Although they are still supported, the new syntax is like the following:

<div>
  <%- include('folder/index', {user: user}) %>
</div>

(See includes Documentation)

Upvotes: 3

Related Questions