Pass variable to EJS include
ejs, node.js
Solution
This feature has been added: if it is not path (file not found), it is evaluated as variable name. https://github.com/visionmedia/ejs/pull/156
Problem
I have a global header used in a couple of places and I was trying to define its location in a variable that could be passed when rendering a template. Something like: ``` var headerLocation = 'some/location/header.ejs'; res.render( viewDir + '/index', { header: headerLocation } ); ``` And in a template file: ``` <% include header %> ``` header being the value passed in with the render. It doesn't seem to be possible but maybe I missed something so thought I'd ask here. EDIT: This is mentioned in comments on answers below but to summarize, this is now available in version 2 of EJS. See here: https://github.com/mde/ejs#includes And related discussion here: https://github.com/tj/ejs/issues/93