Variable in a Jade include cause

I want to include a HTML file in a jade template. The path and name of the file is a variable/parameter which is sent by the server after the user request.

Snippet of index.js

app.get('/material/*', function(req, res){
  var lpath =  "../static/show/" +;  // looks like newSite.html
  res.render("newView.jade", {lpath: lpath});

code of newView.jade

include !{lpath}

but then the browser shows

Error: E:\Git\GitHub\chat-example\views\lecture.jade:1
  > 1| include !{lpath} 
ENOENT: no such file or directory, open 'E:\newSite\views\!{lpath}.jade'
 at Error (native)
 at Object.fs.openSync (fs.js:584:18)

I tested whether lpath is correct and it is. If I add the lpath i that way

include ../static/show/newSite.html

everything is fine. I've also tried the pipe (see Use a variable in a Jade include)


Thanks for any ideas and hints.


Passing lpath to render() will not work. I also had the same problem what you will need to do is compile the files manually and then concatinate then something like

var ejs = require('ejs');
var fs = require('fs');
var path = require('path');

app.get('/material/*', function(req, res){
  var htmlPart = ejs.compile(
      fs.readFileSync(path.join("../static/show/",, 'utf8')); 
  var ejsPart = ejs.compile(
      fs.readFileSync(path.join("../relative_path_to_newView.jade",""), 'utf8'));
  var resBody = htmlPart + ejsPart;

you may use asynchronous functions also hope it helps

Need Your Help

jQuery continuous mousedown

javascript jquery

I have the following code snippets