Pass a partial as a variable

[亡魂溺海] 提交于 2019-12-25 09:22:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!