node.js - Conditionals within script. in jade -


in jade, possible create conditional if statement in dynamicscript section?

for example:

doctype html html  head   script.    -if( locals.display_js )     console.log("display_js true")    -else     console.log("display_js false") 

(locals.display_js parameter pass jade in res.render.)

if display_js true, desired output should like:

<script ...>console.log("display_js true")</script> 

however output is:

<script>  -if( locals.display_js )   console.log("display_js true")  -else   console.log("display_js false") </script> 

it thinking wrong. objective render different javascript functions based on parameters sent res.render.

jade not mess within script block. if need use jade logic inside script block can little tricky , this:

router code:

router.get('/', function(req, res){     res.render('index', {run_this:true}); });  

jade code:

div | <script type='text/javascript'> if(run_this)     | console.log("ran this!"); else     | console.log("didn't run this"); | </script> 

another approach running logic based on jade variables within script tag this:

script.     if(!{run_this}){         console.log("ran this!");     } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -