Loading pages and template from models

I am attempting to load pages and templates from models. The idea is that pages and templates would be created in a CMS and dynamically loaded by the application. Page and Template models are separate as multiple pages may use the same template.

For loading pages, I am doing something similar to what is done in the bitballs example app. I modified the pageComponentConfig to return a promise that resolves to the page rather than returning the page directly.

The pageComponent is also modified to return a promise. I had to move the pageComponent from being a stache helper to the AppViewModel as I don’t believe stache helpers support deferreds.

I then modified the index.stache to wait for the pageComponent to load.

{{#if pageComponent.isResolved}}

I am having less success getting the templates to work with can.Component. Can can.Component be modified to accept a promise? Something like:

exports.Component = Component.extend({
	tag: "player-list",
	template: Template.findOne({ name: 'player-list'}),
	viewModel: ViewModel

Or am I barking up the wrong tree? What would be the best way to accomplish this?

findOne() returning a promise…
so what about waiting until the promise is resolved and that creating that component like that:

Template.findOne({ name: 'player-list'}).then(function(response){

var tpl = can.stache(response.template);

	tag: "player-list",
	template: tpl,
	viewModel: ViewModel