问题
i was wondering how to execute js before rendering?
This fails
-#{somejs} // Outputs just the js-code
p #{somejs()} // Executes the js-code, but doenst render the html
// In EJS I just write. But how can i do this with node?
<%- somejs() %>
// I try to use express-messasges (https://github.com/visionmedia/express-messages) with Jade instead of ejs
回答1:
The following both work for me:
- var test = Math.sqrt(16);
div #{test}
or
div #{Math.sqrt(25)}
If possible, would you please post your somejs()
? Are you certain that it is producing a HTML string?
回答2:
To use express-messages with jade use this code in your template:
- var m = messages()
!= m
回答3:
In jade simply use - someJS()
for more example see the jade website and the in the readme
来源:https://stackoverflow.com/questions/5786674/how-to-execute-js-with-jade