I want to use client-side Jade templates with Backbone. How can i do this?
At the moment, I have successfully configured Backbone (Marionette) to compile Jade templates for use in my views:
Marionette.TemplateCache.prototype.compileTemplate = (tmplStr) -> console.log "jade stuff: ", jade.compile(tmplStr) return jade.compile(tmplStr)
"Problem": I am currently writing templates, for example:
script(type="text/template", id="tmplMainView") | h1= title | p= content
Note the pipes ( | ) that prevent Jade from trying to interpret / analyze them on the server side. How can I fix them?
UPDATE
Maybe I can use the jade --client flag ... but it gives one compiled function: for example
h1= title
Is becoming
function anonymous(locals, attrs, escape, rethrow, merge) { attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge; var buf = []; with (locals || {}) { var interp; buf.push('<h1>'); var __val__ = title buf.push(escape(null == __val__ ? "" : __val__)); buf.push('</h1>'); } return buf.join(""); }
Does this mean that I have to have 1 Jade / compiled JS for each template? How can i use it? Also I think many JS files are a slow way to work? But since all the functions of the template are called anonymous, how can I then contact or somehow work effectively with them?
source share