Jade interpolation in javascript

(Note this is a Scalate Jade, if that matters)

I have the following route:

get("/fruit") { contentType = "text/html" jade("fruity", "fruit" -> "apple") } 

And this fruity.jade template:

 -@ val fruit: String p Alerting #{fruit} :javascript alert("#{fruit}"); 

It looks like this:

 <body><p>Alerting apple</p> <script type="text/javascript"> //<![CDATA[ alert("#{fruit}"); //]]> </script> </body> 

The fruit value is not interpolated for the javascript part. How can I make it allow in javascript?

+4
source share
2 answers

I found that :&javascript or :!javascript will work. This is explained here .

+5
source

If the filters are not interpolated, just use the raw :script tag.

+1
source

All Articles