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...

有帮助吗?

解决方案 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).

其他提示

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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top