Question

I am trying to write a few lines of server side javascript in the jade template engine.

I know for local scripts i can go

 script.
      as many lines as i want...

However i'm looking to do some server side stuff with something like

 -.
      many more lines...

Currently im stuck with

 -var i;
 -for(i = 1, i < 10; i++)
 -{
      -Do things...
 -}

So many dashes...

Was it helpful?

Solution 2

For the server-side in a Jade Template:

Instead of:

-    var i;
-    for(i = 1, i < 10; i++)
-    {
-         // Do things...
-    }

...do...

-
    var i;
    for(i = 1, i < 10; i++)
    {
         // Do things...
    }

You still use the hyphen '-' character, but you simply 'indent' your code. Everything 'indented' is treated as a block (just like normal Jade usage).

OTHER TIPS

Create a static .js file with the content like:

function do_things() {
  var i;
  for(i = 1, i < 10; i++)
  {
    Do things...
  }
}

Then in your template:

-do_things();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top