How to define jade template for using with Backbone

Asked By: Anonymous

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.


Solution

Answered By: Anonymous

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 🙂

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno