I'm using the CoffeeScript filter in Jade on Node.js because I need to insert it into the contents of the script tag I'm generating. I can do this using:
:coffeescript
myNum = '#{locals.myNum}'
On the server, locals.myNum is a number, but I have to quote the escape syntax so it ends up as a string on the browser. I can get around this with parseInt
but there is probably a better way; something like \#{locals.myNum}
would solve my problem but that doesn't work. Right now, I have to call parseInt everytime I put a server-side into my JS during template compile.
Is there a way to have Jade evaluate and output the contents of #{}
without being in a single-quoted string, while compiling the template?
You can do it in a script block instead of :coffeescript and then reference it later in your :coffeescript block. Not the nicest, but an alternative to parseInt.
script
myNum = #{locals.myNum}