Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJS include is not a function Error

On many of my EJS pages I have the following code:

<%- include('elements/fbviewpagepixel.ejs') %>

It works perfectly fine except on this one page. On that one pages it gives me an error saying include is not a function. It looks like I was able to fix it by changing the code above to the following:

<%- include elements/fbviewpagepixel.ejs %>

Why does the first version work on all of my pages except this one? Why does it give me an error on this one page? What is even the difference between the two?

like image 360
Charlie Fish Avatar asked Jun 02 '17 08:06

Charlie Fish


2 Answers

In the later versions of EJS the "client" parameter key is reserved, and will therefore cause this error. Rename the key and it'll resolve your issue.

like image 170
Ben Rolfe Avatar answered Sep 21 '22 09:09

Ben Rolfe


I think, this issus come from parameter passed in list. I had the same issus on rendering my user:

res.render("profil-client.ejs", {
    client: myClient
});

But when I rename my parameter like this:

res.render("profil-client.ejs", {
    r_client: myClient
});

No more error. I'm not sure, but I think ejs use attribute "client" for internal usage. So I just rename my parameters...

like image 22
James Deschênes Avatar answered Sep 23 '22 09:09

James Deschênes