I use node.js on server side, express.js and jade. I have written a small wrapper function to fill jade templates on the client side. I think I'll use requireJS and jQuery on client side, but have not decided yet. Now, the task that I have to do many times is
Note: there are tons of template engines, and my question is not about a template engine, but about an easy workflow.
I have to do it this way:
var get_data = function (tpl) {
$.get(url, function(data) {
$('#target_element').html(jade.render(tpl, {locals: data}));
});
};
if (!'template_name' in _cache) {
$.get('template_name', function(tpl) {
_cache['template_name'] = tpl;
get_data(tpl);
});
}
else {
get_data(_cache['template_name']);
}
(in this example, the template and data are fetched synchronously, which is not nice)
I'd like to have a code like this:
render_template('template_name', 'url?arguments=values', {replace: '#element_id'});
(it's similar to MongoDB syntax)
Is there a simple framework or a jquery module to do this work?
I'm not sure if it fits your requirements completely, but PURE is a nice templating engine for you to consder:
http://beebole.com/pure/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With