static javascript not rendering in jade (with express/node.js)

前端 未结 4 532
误落风尘
误落风尘 2021-01-19 14:43

I hope you are well.

I\'m suddenly unable to render any external javascript in jade templates! To get to the bottom of things, I stripped it down to the bare minimum

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 15:02

    you need to pass your script from the controller like that:

    app.get('/', function(req, res){
      res.render('index', { title: 'Express', scripts: ['javascripts/script.js']});
    });
    

    and then in your head in layout.jade:

    - each s in scripts
        script(src=s)
    

提交回复
热议问题