I am new using dustjs and I want to use it to render a template with information from mongo using mongoose.
So I have:
A template:
{"This object property {object1} is loaded from db"}
object1 is a string loaded with mongoose from mongodb
I need a generic function with some parameters in the context to make the query. Something like
{
object1: function(objectid){
Object.findOne({_id: objectid},function(err,ob){
return ob.property;
})
}
}
Is that possible with dustjs?
Thanks
I'm not sure i understand what you want to do, but if you want to pass in a parameter, you're looking at probably defining a section instead of just a context.
you could do this:
{"This object property {object1 objectid="1"}{.}{/object1} is loaded from db"}
and your method in the context will have to have these parameters:
object1: function(chunk, context, bodies, params){
var objectid = params.objectid;
<the rest of your code>
return chunk.write(ob.property)
}
if a parameter is what you're looking for, dust will only allow parameters for sections. and you can do this no problem. good luck.