I am seeking guidance on the recommended approach for nesting Backbone Views.
Here are some possible methods for nesting views:
- Rendering all views and assembling them in the Router
- Having an IndexView handle all nesting, which is then called in the router
- Including views in Underscore templates
I have already experimented with this concept in the following fiddle: http://jsfiddle.net/m48Nc/2/
Note: I am aware that the example does not function properly; it merely displays the current structure that I have been working on but am not satisfied with.
Which method should I pursue? Any relevant links or resources would be appreciated ;)
UPDATE:
Based on responses from fguillen and other discussions I came across, we can achieve the following:
var IndexView = Backbone.View.extend({
tagName: "div",
className: "container",
template: LayoutTemplate,
render: function() {
this.$el.html(LayoutTemplate);
this.$('div.content').html(ContentTemplate);
this.$('div.sidebar').append(new LoginView().render().el);
this.$('div.sidebar').append(new RegistrationView().render().el);
return this;
}
});