Accessing Express.js req or session from Jade template

后端 未结 7 1248
南方客
南方客 2020-12-13 18:49

I am wondering if there is an easy way to access Express.js\' req or session variables from within a Jade template without passing it in through the normal response.

7条回答
  •  萌比男神i
    2020-12-13 19:29

    While there is always a way in javascript to escape the scope and crawl upwards, I really really really really really strongly encourage you to find another way.

    Consider what you're asking: Can I have my view know about the guts of my controller?

    Or what you're really asking: Can I have my view know about the guts of my runtime?

    A view is supposed to take data and transform it into markup. That's IT. If you do anything else, you're doing it wrong. I don't care how "easy" it is. That's the point of an interface. To define exactly what is being passed, and to make it easy to replace one thing with another thing.

提交回复
热议问题