Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epoxy with Template #70

Open
adrianboston opened this issue Feb 11, 2014 · 4 comments
Open

Epoxy with Template #70

adrianboston opened this issue Feb 11, 2014 · 4 comments

Comments

@adrianboston
Copy link

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

@gmac
Copy link
Owner

gmac commented Feb 11, 2014

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.

@gmac gmac added the duplicate label Feb 11, 2014
@gmac
Copy link
Owner

gmac commented Feb 11, 2014

Also, this is a duplicate of #27.

@adrianboston
Copy link
Author

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.

@Prinzhorn
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants