How can a Jade template use client-side global variables?

前端 未结 1 375
野的像风
野的像风 2021-01-12 19:52

Lets say I have a browser open, and in JavaScript I declare a global variable.

window.myGlobalVar = \'Hello!\';

I then compile a jade templ

相关标签:
1条回答
  • 2021-01-12 20:00

    You can pass the names of the globals, you want to use in jade templates, with the options object to the compile function. See jade api docs: http://jade-lang.com/api/

    jade.compile(template, { globals: ['globalone','globaltwo']})
    

    See this fiddle to see it in action: http://jsfiddle.net/lchngr/J5WJb/5/

    0 讨论(0)
提交回复
热议问题