I want to load the contents of a partial view (written in Jade) into a Bootstrap modal dialog. For this, I use an AJAX call. I could return only the generated HTML and load it into the modal, but there's additional data I need to get along with the rendered view. I would like to be able to return an object like this (parsed to JSON) :
response = {
some_data: 'blablabla',
some_more_data: [5, 8, 10, 67],
my_html: '<div>HTML rendered from the Jade template</div>'
};
Is there a way to do this? For now I can return the rendered HTML like this :
res.render('employees', {layout: false});
But how can I store it in a variable to return along with more data, without having to do more AJAX calls?
In express you can use app.render with a callback to render a view and get the html:
app.render('employees', {layout: false}, function(err, html){
var response = {
some_data: 'blablabla',
some_more_data: [5, 8, 10, 67],
my_html: html
};
res.send(response);
});
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