I am working on a custom framework using Handlebars and i would like to automatically generate data for my partials.
I have a template using a partial like this :
partial.hbs :
<strong>We are {{status}}</strong>
template.hbs :
<h1>Hello {{name}}</h1>
{{>partial partialData}}
I can compile it using :
var partial = Handlebars.compile("<strong>We are {{status}}</strong>");
Handlebars.registerPartial('partial', partial);
var template = Handlebars.compile("<h1>Hello {{name}}</h1>
{{>partial partialData}}");
var result = template({name: "Harry", partialData: { status: "friend" } });
Now I would like to remove partialData from the template and just call
{{>partial}}
And the value of status would still be added in my JS code.
How can I do this ?
question from:
https://stackoverflow.com/questions/65877399/how-to-hack-handlebar-partials-data 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…