I'm trying to make a tag that behaves differently based on the route, but when I try to render html within a @{ ... } block, I can't seem to insert my variables correctly.
@(route: String, on_image: String, off_image: String, alt_text: String)
@{
val Pattern = ("(" + route + ".*)").r
val path = request().path()
path match {
case Pattern(foo) => {
if(path != route && route == "/") {
<script type="text/javascript">
alert("{route}");
</script>
} else {
<script type="text/javascript">
alert("{route}");
</script>
}
}
case _ => {
<script type="text/javascript">
alert("{route}");
</script>
}
}
}
When I load the page, I get a syntax error in my Firebug console, where it's revealed that the content of the script tag evaluated to this:
alert("/accounts");
Now, I've tried things like @Html{ ... } and @Html( ... ) and @Html({ ... }) surrounding the whole block. I've also tried alert(@Html("{bar}")); and other similar things, but everything produces various errors.
What's the right way to do this?
Edit
Updated to show trying to use only one variable for simplicity's sake, and showing where that variable comes from.
"@foo"