Rendering underscore variables in Jade

I included the assets described in this ticket , and Underscore variables work, except when inside the tags. I can’t get variables for rendering inside dynamic data-id=someid to execute onClick events with basic events.

In standard HTML:

 <script type="text/template" id="template-action1-thing"> <tr> <td class="action-td" style="width: 10%;"> <button id="do-remove" data-id="<%= obj.id %>">X</button> </td> </tr> </script> 

With (Scalate) Jade that doesn't work:

 script(id='template-action1-thing' type='text/template') p <%= obj.id %> Will render tr td.action-td(style='width: 10%;') button(id='do-remove' data-id='<%= obj.id %>') | X 

If I am this one , the actual html displays with the variable correctly, although incorrectly:

 tr td(style='width: 10%;') button(id='do-remove_thing' data-id='myid') X 

With a template like:

 script(id='template-action1-thing' type='text/template') | td.action-td(style='width: 10%;') | button(id='do-remove_thing' data-id='<%= obj.id %>') X 
+4
source share
3 answers

If you want to use the underline pattern in jade, you need to modify the pattern to look like this:

 script(id='template-action1-thing' type='text/template') | <tr> | <td class="action-td" style="width: 10%;"> | <button id="do-remove" data-id="<%= obj.id %>">X</button> | </td> | </tr> 

Or you could use jade templates instead of underline patterns.

+3
source

I know that this question has already been answered, but in search of a more eloquent solution, I found that this also works:

 script(type='text/html', id='tpl-name') h3!='<%= foo %>' p!='<%= bar %>' 

This allows you to use the Jade syntax.

+10
source

Now we can use the script. to insert a block of plain text, as described here: http://jade-lang.com/reference/plain-text/ .

 script(id='template-action1-thing' type='text/template'). <tr> <td class="action-td" style="width: 10%;"> <button id="do-remove" data-id="<%= obj.id %>">X</button> </td> </tr> 
+2
source

All Articles