0

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.

Joost Döbken
  • 2,870
  • 1
  • 28
  • 64

1 Answers1

0

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)
Aron
  • 7,221
  • 4
  • 27
  • 49