Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Include function is not being processed #9

Open
nicib83 opened this Issue May 26, 2013 · 8 comments

Comments

Projects
None yet
5 participants

nicib83 commented May 26, 2013

I've been trying to use the include function, however it seems like it's not being parsed correctly, any idea what i am missing ? thx.

Error: ENOENT, no such file or directory '/projects/http/templates/("partial.ejs", { partial: 1 })'
    at Object.fs.openSync (fs.js:427:18)
    at fs.readFileSync (fs.js:284:15)
    at Object.exports.parse (/projects/node_modules/ejs/lib/ejs.js:159:19)
    at Object.exports.compile (/projects/node_modules/ejs/lib/ejs.js:223:15)
    at compile (/projects/node_modules/templar/templar.js:156:25)
    at output (/projects/node_modules/templar/templar.js:133:11)
    at ServerResponse.template (/projects/node_modules/templar/templar.js:100:15)
    at Object.about [as fn] (/projects/http/routes/about.js:16:9)
    at Server.site (/projects/http/site.js:66:9)
    at Server.EventEmitter.emit (events.js:98:17)
Owner

isaacs commented May 26, 2013

Share your EJS file. Otherwise, I have no idea.

nicib83 commented May 26, 2013

i was basically just trying to include the header like in your repo

<%- include('header.ejs', locals) %>

This works just fine
<%- include header.ejs %>

Owner

isaacs commented Jul 3, 2013

What EJS parser are you using? That's really weird. It works fine for me on npm-www like this.

I have the same issue. It seems to be a naming conflict with EJS, since renaming the include function in templar solves the problem completly:

// tplData.include = include(f, tag) // old
tplData.require = include(f, tag)

:~$ npm show ejs version
0.8.4

Owner

isaacs commented Jul 5, 2013

So, there's something in your template data called "include"? Yes, that would probably collide with Templar's include function.

khugin commented Jul 6, 2013

(Sorry, wrote with the wrong account before)

Actually no - I tested whitout any data at all:

Similar to your npm-www setup, response is decorated with Templar:

response.template = Templar(request, response, {
    engine: ejs,
    folder: Path.resolve(__dirname, 'templates'),
    cache:  false
} )

And then later, used:

response.template('test.ejs', { } )

Of course, I didnt try a 'minimal' setup, and there's code inbetween - but I'm pretty sure that it doesnt add anything called include.

This part in EJS seems to search for an 'include' and handle it: (line 155+)
https://github.com/visionmedia/ejs/blob/master/lib/ejs.js

  if (0 == js.trim().indexOf('include')) {
    var name = js.trim().slice(7).trim();
    if (!filename) throw new Error('filename option is required for includes');
    var path = resolveInclude(name, filename);
    include = read(path, 'utf8');
    include = exports.parse(include, { filename: path, _with: false, open: open, close: close, compileDebug: compileDebug });
    buf.push("' + (function(){" + include + "})() + '");
    js = '';
  }

Of course, I didnt have much time to look into it, so it's just a guess. But it really seems to be an EJS update.
tj/ejs@fb4c039#lib/ejs.js

Owner

isaacs commented Jul 8, 2013

Yes, the issue is an EJS update that added an include keyword.

As a workaround you can use e.g. locals.include("file.ejs", {param: 1})!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment