I'm trying to pick a JS template engine for an upcoming project and one of my favorites seems to be dust.js.
I like the idea that it's asynchronous, i.e. I just stage some template for rendering and when it's ready the callback inserts the rendered HTML into the DOM.
I'm not sure however how to work around the problem of asynchronous rendering within synchronous callbacks. For example - I often use DataTables plugin which provides some callbacks allowing me to modify DOM nodes before they are actually inserted.
To illustrate the problem - let's assume I have a following snippet (taken and modified from DataTables website):
$(document).ready( function() {
$('#example').dataTable( {
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
// modify the node before it's actually inserted into the document
$('td:eq(4)', nRow).html( '<b>' + aData[4] + '</b>' );
}
} );
} );
Now - I would like to get rid of '<b>' + aData[4] + '</b>' and use a template rendered with some context instead (it's a trivial example but shows the issue).
If I understand correctly I can't force dust.js to render the template synchronously, so it might happen that an unprocessed node will be inserted into the document (and users will see it unprocessed) and later on when dust.js actually renders the template that node would be modifed.
This obviously wouldn't look good from the user standpoint.
So is this really the case (that dust.js can't be forced to be synchronous) and if yes - how to cope with that? Should I use synchronous engine, like handlebars or mustache or maybe I'm not seeing something obvious here?
Any help or insight or advice would be very welcome. Thanks! :)
EDIT:
This question is not about how to render a template, but about how to make sure it's rendered before the fnRowCallback finishes. Thanks @robertklep for pointing this out with your (deleted) answer.
fnRowCallbackfinishes, so if that's really an issue I don't think Dust.js is usable. - robertklep