backbone.epoxy
backbone.epoxy copied to clipboard
Epoxy with Template
Do you have any pointers concerning epoxy with underscore template -- whereby html is passed in via string.
as such. define([ 'jquery', 'underscore', 'backbone', 'epoxy', 'text!views/MyTemplate.html'
], function($, _, Backbone, Epoxy, Template ){
var MyView = Epoxy.View.extend({
template: _.template(Template),
bindings: {
".brand-name": "text:name",
".brand-name": "text:count",
},
// Perhaps render not needed given that epoxy bindings
render : function() {
var data = {
item: this.model,
_: _
};
this.$el.html( this.template(data) );
return this;
}
return MyView;
});
and does one need a render method anymore..!
thanks and apologies for sending email. didnt see this forum. regards
No, unfortunately. There's no formalized way of passing in a string template or swapping out a bound template. That template binding is quite primitive actually... The difficulty is not so much the binding itself as the inputs INTO the binding. That binding requires model data (easy) and string data for the template... which certainly doesn't belong as a model field.
Ironically, I don't use Epoxy very often myself (built it for one project over a year ago), so I'm not very proactive about coming up with use-cases for it. If you can propose an API for how you'd like to define and control template bindings, please propose it. I'd happily take it into consideration.
Also, this is a duplicate of #27.
i dont think its a template bindings issue. its simply getting some cursed html (text) into a View object. it could be achieved by way of an el function as suggested by a post in the duplicate post #27. epoxy seems pretty cool. what are you using as an alt model binding thingy.
As I said (and you read) in #27, using a function for el is actually great. I do this everywhere, not just for el.
In your case it could be as simple as swapping template: _.template(Template) with el: function() {return Template}. You shouldn't bee needing underscore templates or render at all when working with Epoxy.