How to execute js with Jade?

安稳与你 提交于 2019-12-22 09:56:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!