ario
ario

Reputation: 1787

Include the contents of other files when rendering jade in Express?

I have the following layout.jade:

!!!
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body!= body

In the body, I'd like to include the contents of another file, content.jade.

I'm trying something like this in app.js:

app.get('/test', function(req, res){
  res.render('layout', {
    layout: false,
    body: include content.jade
  });
});

but it gives SyntaxError: Unexpected identifier at 'content'. Is there a way to do this?

Upvotes: 1

Views: 776

Answers (1)

mna
mna

Reputation: 23963

You have to render your content (body) file, not the layout. With the layout: true param (which is the default, I think) jade will automatically use layout.jade to render the "frame" of your page, and then feed your content in the body variable, passed to the layout ( see Expres doc ). so:

res.render('content');

should do the job.

Upvotes: 4

Related Questions