Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

javascript - How to hack handlebar partials data

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...