ejs icon indicating copy to clipboard operation
ejs copied to clipboard

Error using include with node webkit (possible bug)

Open setitesuk opened this issue 12 years ago • 2 comments

I am writing a node webkit application where I am using EJS to template the html

I hit a bug with include, which throws an error

template.ejs <% include app/views/prev_next_buttons %>

console output: Uncaught Error: filename option is required for includes /private/var/folders/x2/pkyj9bsj48l4h57hk38cszjh0000gq/T/.org.chromium.Chromium.tWcdZU/node_modules/ejs/lib/ejs.js:157

Checking this line out (and the block of code it is in Line 155: 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 = ''; }

Changing line 157 to

if (!name) throw new Error('name option is required for includes');

Then the problem goes away.

Even attempting to add options with a filename in doesn't work

<% include ('metrichor/views/prev_next_buttons', { filename : '' }) %>

I use EJS with Express and there I don't have this problem.

Cheers

Andy

setitesuk avatar Sep 02 '13 15:09 setitesuk

Yep, simple, you have to add the filename option when you call the method to render the EJS or use renderFile rather than render. This is either a bug in your code (likely) or in node-webkit (less likely) but it is not a bug in ejs, which sensibly refuses to allow you to have your includes be relative to the current working directory.

ForbesLindesay avatar Sep 10 '13 17:09 ForbesLindesay

I figured I was most likely something in my code, but couldn't work out what. I'll try your suggestions and see where I get to. Thanks for your response. We are all relatively new to this node stuff, but enjoying the change from our usual development tech.

setitesuk avatar Sep 10 '13 23:09 setitesuk