Json objects do not render properly
DiwasPandey opened this issue · comments
Current implementation of handlebars does not render a template with json objects properly. For example :
use handlebars::Handlebars;
use serde_json::json;
let source = "This is a json Object : {{name}}";
let mut handlebars = Handlebars::new();
let data = json!({"object": {"name": "object", "type":"object"}});
let result = handlebars.render_template(source, &data).unwrap();
println!("{}", result);
the above code produces the following output :
This is a json Object : [object]
where the desired behaviour is the following :
This is a json Object : {"name": "object", "type": "object"}
Upon further investigation, the issue seems to be related to code here. I am not sure why the current implementation exists this way. Changing this line to the line below should solve the issue, since serde_json::Value
already supports to_string()
method.
Json::Object(_) => self.to_string()
Sorry for late response. This behaviour is aligned with original JavaScript implementation of handlebars. If you really want to render an object, just convert it to string or write a helper for that.