I'm creating an unordered list element in Backbone via Underscore templating:
<ul id="FrontRack" style="
background-image: url({%= data.get('racks').at(0).get('imageUrls')[0] %});
height:{%= data.get('racks').at(0).get('pixelHeight') %}px;
width:{%= data.get('racks').at(0).get('pixelWidth') %}px;
">
<li>Hello World</li>
</ul>
I'm wondering two things:
- Is setting
style
still considered bad practice when creating elements through templating? - Should I be setting the style using jQuery after I generate the HTML from the template? This would be done inside of Backbone's render instead of inside of the template.
Something like:
render: function () {
this.$el.html(this.template(this.model.toJSON()));
this.$el('#FrontRack').css({ backgroundImage: ... }); // Example
return this;
}