How to define jade template for using with Backbone
backbone.js, express, node.js, pug
Solution
That's easy, but there's one catch: You don't want Jade to escape attributes content so use `foo!='<%= bar &%>'` instead of just `foo='<%= bar &%>'`.
Here we go:
script#itemTemplate(type='text/template')
img(src!='<%= photo %>', alt!='<%= name %>')
h1 <%= name %>
span <%= type %>
div <%= address %>
dl
dt Tel:
dd <%= tel %>
dt Email:
dd
a(href!='mailto:<%= email %>') <%= email %>
It's tested, so you can use it right away :)
Problem
I need to use template for rendering of each ItemView: ``` var ItemView = Backbone.View.extend({ className: 'item', template: _.template($('#itemTemplate').html()), initialize: function () { } }); ``` So I need to define html template at first: ``` <script id="itemTemplate" type="text/template"> <img src="<%= photo %>" alt="<%= name %>" /> <h1><%= name %><span><%= type %></span></h1> <div><%= address %></div> <dl> <dt>Tel:</dt><dd><%= tel %></dd> <dt>Email:</dt><dd><a href="mailto:<%= email %>"><%= email %></a></dd> </dl> ``` But I use Nodejs Jade Template Engine and I don't understand how shuold I define in it. Help please.