elabs/serenade.js — Issue #17: Provide subviews when rendering instead of via globals
Author: augustl
Created: 2012-02-10 10:36:13+00:00
State: open

Currently, a view needs to be made globally available with `Serenade.view("my_view", tmpl)` when subviews are used. This also puts some restrictions on what the controller can be - it currently has to be a constructor, for example.

It would be better if the subviews could be provided to `aView.render`.

var view = Serenade.view(tmpl);
var element = view.render(model, controller, {
myView: function (model) {
return otherView.render(model, myOtherController);
}
});

In the template we have `- view myView`. This will cause myView to be called on the 3rd argument passed to `render`. This function is assumed to return a DOM element, such as the DOM elements `render` on another view will provide.

I think having a 3rd argument for this is better than using the controller, since view names might conflict with what you otherwise have on your controller.

The `model` passed would be the current model, be it for the template root or the current collection model.