question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

include API force EJS template path as a root path

See original GitHub issue

I 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):

  1. relative path - WORKS

// mytemplate = 1/template.ejs

  1. 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:closed
  • Created 7 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanZimcommented, Aug 25, 2016

@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.

1reaction
m-pawelczykcommented, Aug 25, 2016

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EJS include file relative to project root - node.js - Stack Overflow
So rather mentioning the relative path at every include i declare a variable rootPath ... In both cases the values are simply available...
Read more >
Using EJS Template Engine With Express.js - Topcoder
Open up the terminal and create the project directory. mkdir ejs-starter. Then, navigate to the directory. cd ejs-starter.
Read more >
Node.JS Client App Tutorial - Developer Portal
EJS is configured to work with the templates stored in the views subdirectory of your main application directory. To enable the view templates....
Read more >
Node.js Support | Plesk Onyx documentation
Document Root. Here you can set the domain's document root directory, which must be a subdirectory of the application root directory, specified below....
Read more >
Express Tutorial Part 2: Creating a skeleton website
The views (templates) are stored in the /views directory (as specified in app.js) and are given the file extension .pug. The method Response....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found