How can I render inline JavaScript with Jade / Pug? How can I render inline JavaScript with Jade / Pug? express express

How can I render inline JavaScript with Jade / Pug?


simply use a 'script' tag with a dot after.

script.  var users = !{JSON.stringify(users).replace(/<\//g, "<\\/")}

https://github.com/pugjs/pug/blob/master/examples/dynamicscript.pug


The :javascript filter was removed in version 7.0

The docs says you should use a script tag now, followed by a . char and no preceding space.

Example:

script.  if (usingJade)    console.log('you are awesome')  else    console.log('use jade')

will be compiled to

<script>  if (usingJade)    console.log('you are awesome')  else    console.log('use jade')</script>


Use script tag with the type specified, simply include it before the dot:

script(type="text/javascript").  if (10 == 10) {    alert("working");  }

This will compile to:

<script type="text/javascript">  if (10 == 10) {    alert("working");  }</script>