0

I'm trying to pass a variable from express to my Jade view like so:

From my server.js:

app.route('/').get((req, res) => {
  res.render('index', { md: 'index' });
});

To my .pug:

html
  body
    block content
      include:marked ../md/#{md}.md

I just keep on getting an error about 'no file #{md}'

gandreadis
  • 3,004
  • 2
  • 26
  • 38
Drew
  • 1,171
  • 4
  • 21
  • 36

1 Answers1

0

This is a known issue. As far I can tell from that issue report, this functionality is simply not supported at the moment by the Pug system. It is, however, "on the roadmap for 3.0.0".

Edit: See this SO question, as well. It also relates to the same issue of variables in includes.

gandreadis
  • 3,004
  • 2
  • 26
  • 38
  • You could have a look at the workaround presented in the first answer of the question I linked (http://stackoverflow.com/a/12133319). It proposes prerendering the content you want to include and then passing the rendered html to the template as context variable (not the cleanest way, but should work). – gandreadis Jan 07 '17 at 21:20
  • Yea, that work around worked, kinda sucks though, hopefully pug 3 comes soon. – Drew Jan 07 '17 at 22:08