传递一个局部变量 [英] Pass a partial as a variable
本文介绍了传递一个局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将一个局部变量传递给另一个局部变量?
类似于:
{{>
template1
image =images / image1.jpg
content = template2
}}
动态部分:
如果
您的模板将不得不调用 template1
并将它们的动态部分名称作为字符串传递:
{{> template1 content =template2}}
您的 template1
部分必须包括以下内容:
{{> (lookup。content)}}
Is it possible to pass a partial as a variable to another partial? Something like:
{{>
template1
image="images/image1.jpg"
content=template2
}}
解决方案
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")}}
这篇关于传递一个局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文