5

I am using node.js and express.j s to render an index.jade page which contains several script blocks taht contain templates to be used via backbone and underscore. The issue I am facing is that due to the inclusiong of <%= %> style variables within the templates, the Jade rendering is failing. The following code snippet causes a syntax error:

script#tpl-things-list-item(type='text/template')
  td 
    a(href=<%= _id %>) link text
  td <%= name %>
  td <%= age %>

Note that it is only a problem when I use a variable inside the href value, if I remove the entire href, this snippet works just fine. Is there a way to work around this? I'd like to continue using Jade to define the templates as it is very concise but this is a show stopper.

1
  • I can't figure this out either. strange. Commented Nov 22, 2012 at 0:19

1 Answer 1

3

Got it.

!!! 5
html(lang='en')
    head
        title= title
    body
        h1= "Hello World!"
        script#tpl-things-list-item(type='text/template')
            td
                a(href!="<%= _id %>") link text
            td <%= name %>
            td <%= age %>
5
  • What does the "!" before the "=" in the href call do?
    – nickbona
    Commented Nov 22, 2012 at 16:50
  • it generates 'unescaped executable code' github.com/visionmedia/jade#readme Commented Nov 23, 2012 at 15:01
  • for me, this prints the literal string, e.g. a href!="<%= _id %>" instead of a href="123". any suggestions? my full script is: script(type='text/template') a(href!="<%= _id%>")<%= _id%> Commented Jun 25, 2013 at 19:15
  • i found a workaround by just using | but that doesn't seem as clean :/ e.g. |<a href=<%= _id %>> <%= _id%></a> Commented Jun 25, 2013 at 19:35
  • Seems like just the quotes around the href value should be enough, since client-side templating is not "unescaped executable code". I've successfully used angular.js interpolation in jade templates with just a(href="{{ url }}"). Commented Sep 6, 2014 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.