<head> #set($test = "works")) </head>
<script> 
    var get = "${test}"; // I also tried using '$test' and "$test" also
    alert(get);
</script> 
And it alerts out ${test}, but should print works.
How can I get it to work?
try this...
    #set ($test = "works")
  <script type="text/javascript">
       var myvar = "${test}";
       alert (myvar);
  </script>
THIS WORKS SURELY!!!!
Try var get = "$test"; instead of var get = "${test}";
I realize the question is old, but this worked for me:
#set ($test = "hi")
<script>
    alert("$test");
</script>
Need to include quotes around the variable in the alert since it is a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With