I can find solutions to pass local variables from jade to javascript, for example:
script.
var myVar = `#{myVar}`;
script(src=src)
But since I want to use my jade template for many views, with different sets of variables, I wonder if it is possible to pass ALL available local variables.
Going off the answers to this question it doesn't look like there's a clean way of getting all variables in scope.
In which case you're best off gathering all variables you want to pass to your jade/pug in a single object and then pass that object to the pug file.
const holder = {};
holder.one = 1;
holder.two = 2;
pug.compile(page, holder);
You can then do
script.
var one= `#{one}`;
script(src=src)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.