Node JS Pass a Variable to Jade / Pug

前端 未结 2 708
我寻月下人不归
我寻月下人不归 2020-12-16 11:33

For some reason I can\'t pass a variable to the pug template with Node JS.

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


        
2条回答
  •  孤街浪徒
    2020-12-16 12:02

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

    follow the lines below:

    1. use this first

      app.set('views', __dirname + '/public/views'); app.set('view engine', 'pug');

    2. thEn pass this to first visit

      app.get('/', function (req, res) { res.render('index', { title: 'Hey', message: 'Hello there!'}); });

    3. thEn echo in template file "index.pug" in "/public/views"

      html head title= title body h1= message

提交回复
热议问题