Node JS Transfer Variable to Jade / Pug

For some reason, I cannot pass the variable to the pug template using Node JS.

app.get("/", function (req, res) { res.render('index', { hello : 'Hey'} ) }) 

....

 extends layout.pug block content h1 #{hello} guy 

It just returns "guy" in the index.html file

+6
source share
2 answers

I think you are using JADE coding (# {hello}) with the "pug" plugin (updated jade) with static .html - completely wrong.

run the following lines:

  • use this first

     app.set('views', __dirname + '/public/views'); app.set('view engine', 'pug'); 
  • how to convey this on your first visit

     app.get('/', function (req, res) { res.render('index', { title: 'Hey', message: 'Hello there!'}); }); 
  • than echo in the template file "index.pug" in "/ public / views"

     html head title= title body h1= message 
+6
source

perhaps you should set the code as ...

 app.get("/", function (req, res) { res.render('index', { 'hello' : 'Hey'} ) }) 
-one
source

All Articles