问题
Is it possible to pass a partial as a variable to another partial? Something like:
{{>
template1
image="images/image1.jpg"
content=template2
}}
回答1:
If I correctly understand what you are asking, then I think your question is answered in the Handlebars documentation on Dynamic Partials:
If a simple variable has the partial name, it's possible to resolve it via the lookup helper.
Your template would have to call template1 and pass they dynamic partial name as a string:
{{> template1 content="template2"}}
Your template1 partial would have to include the following:
{{> (lookup . "content")}}
回答2:
Try to pass it as a string
{{> template1 tempPartial="template2"}}
And then reference it with
{{> (tempPartial) }}
来源:https://stackoverflow.com/questions/42301283/pass-a-partial-as-a-variable