Node JS Pass a Variable to Jade / Pug

前端 未结 2 704
我寻月下人不归
我寻月下人不归 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:04

    Try this.. works for me.

    nodejs part / index.js

    const router = require('express').Router();
    router.get('/', (req, res, next) => {
        const testObj = {hello: 'Hey'};
        res.render('index', { testObj: JSON.stringify(testObj) });
    });
    

    pug/jade part / (index.pug)

    script.
        var testObj = !{testObj};
    

    i'm using pug version: 2.0.3

提交回复
热议问题