include API force EJS template path as a root path
See original GitHub issueI have discovered problem with EJS API. It looks like EJS API changed between versions 2.4.1 and 2.5.1. In version 2.5.1 function include always add EJS template path to given path value. In version 2.4.1 behavior was diffferent.
I use express
and views
path is set as a argument:
var express = require('express');
app = express();
app.set('views', path.join(__dirname, '/../views'));
app.set('view engine', 'ejs');
Then I use function render:
var renderObj = var renderObj = {
mytemplate: relative path OR absolute path // examples of this values is shown below
// (...)
};
res.render('layout-main', renderObj);
Let’s look hot it works now (2.5.1):
- relative path - WORKS
// mytemplate = 1/template.ejs
- absolute path - DOESN’T WORK
// mytemplate = /2/template.ejs
error: Error: /opt/myapp/frontend/lib/views/layout-main.ejs:129
>> 129| <%- include(mytemplate) %>
ENOENT: no such file or directory, open '/opt/myapp/frontend/lib/views/2/template.ejs'
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (1 by maintainers)
@m-pawelczyk I merged the fix, just need to wait for @mde to push a release; I don’t have npm publish rights.
You will need to run
npm uninstall mde/ejs#fix-196 && npm install ejs
after this fix is included in a release.@RyanZim thank you very much for fast investigate. Your fix (https://github.com/mde/ejs/tree/fix-196) works OK for me. Thanks.
@cnwhy Fortunately, I have found it on my CD environment.