4

(Note, this is the Scalate Jade, if that makes a difference)

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 renders like so:

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

The fruit value is not interpolated for the javascript portion. How can I get it to resolve in javascript?

Synesso
  • 37,610
  • 35
  • 136
  • 207

2 Answers2

5

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

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Synesso
  • 37,610
  • 35
  • 136
  • 207
  • Very interesting! I don't think it's supported in the official compiler, however – Ven Apr 16 '13 at 20:13
  • 1
    FYI, [here](http://scalate.github.io/scalate/documentation/jade-syntax.html#Filter_Interpolation) is an updated document link (original no longer seems to be working). – Matt Hagopian Oct 14 '14 at 15:36
1

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

Ven
  • 19,015
  • 2
  • 41
  • 61