Let me elaborate on my setup:
I have precompiled dust.js templates that I would like to use with Backbone.LayoutManager.
Backbone.LayoutManager uses the following configuration:
Backbone.LayoutManager.configure
manage: true
fetch: (name) ->
name
So the name of the template is passed through fetch straight to render, and I’d like to override render like this:
render: (template, context) ->
done = @async
dust.render @template, context, (err, out) ->
throw err if err
done(out)
But I cannot do this with render (presumably because the LayoutManager author assumed that template rendering would be synch).
Does anyone know how I could accomplish this?
You’ll need to modify the LayoutManger to handle asynchronous rendering of templates.
One of the ways to do this is to use the jQuery Deferred object where the call to
renderreturns an instance of aDeferredobject, which you then resolve in the call to theDustlibrary.Then, modify Backbone.LayoutManager to NOT continue doing what it wants to with the templates until that Deferred object has been resolve.
in
render:You then take the method in Backbone.LayoutManager that calls render and instead of doing something with the return from render you attach that “something” to the
donehandler for the deferred you passed back.I’m using Marionette.js (along with it’s async variant) and dust, this is what my core
rendermethod looks like:(Obviously not using coffeescript either…)