Jeremy Jeremy - 1 year ago 69
Javascript Question

Underscore/Backbone Templates .get

Is it possible to use

in an underscore/backbone template?


Passing data to the template:

var pageTemplate = _.template( PageTemplate, this);

The template it's self:

<div id="productContainer" style="left:<%= 1 + (450 - model.get('previewHeight'))/2 %>px;"></div>


Answer Source

Yes, it should be possible.

var my_json = {};
my_json.model = my_model;

var html_template = _.template($("#my_template").html());

<div id="my_template" style="left:<%= 1 + (450 - model.get('previewHeight'))/2 %>px;"></div>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download