Is it possible to run custom JavaScript in EJS templates?
I'm looking for the equivalent of the following Jade code:
- var Fs = require("fs")
- var foo = 42;
| #{foo}
This will create the Fs
and foo
variables and display 42
.
Does EJS have this power?
From what I see, the following snippet does the same thing (without requiring the fs
package):
<% var foo = 42; %>
<%= foo %>
Is this the right way or is there a better solution?
Yes it is!
As you can see here http://www.embeddedjs.com/
In the example they are writing things from an array