Question

I am using Genshi template engine in the Turbogears2 web framework. While writing the simple javascript if statement, I am getting the error "Unexpected token ; ". I am comparing few things in the table and printing its value if it is greater than some value. It is similar to this code:

"var c = 4;
if (c > 3) {
console.log(c); }"

Could someone help me out from this problem.

Thanks

Was it helpful?

Solution

Always emit your javascript in CDATA sections:

<script>
//<![CDATA[ 
var c = 4;
if (c > 3) {
  console.log(c); 
}
//]]>
</script>

That way they will be correctly handled while still making possible to use ${} expressions inside your JS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top