简体   繁体   English

将上下文传递给Handlebars部分

[英]Passing context to a Handlebars partial

I wish to pass the parent templates context to a handlebars partial. 我希望将父模板上下文传递给句柄部分。

I register my partial in app.js with the following 我用以下内容在app.js中注册我的部分内容

Handlebars.registerPartial("lifestyles", Handlebars.templates['partials/product-lifestyles']());

I then render my partial inside my main template file like the following, passing in this as a second parameters of which I understand it should pass in the context of the parent 然后我将我的部分内部渲染到我的主模板文件中,如下所示,将其作为第二个参数传递,我理解它应该在父文件的上下文中传递

{>lifestyles this}}

I have a log helper which console logs a parameter, inside my partial I log out this, it returns undefined. 我有一个日志帮助器,控制台记录一个参数,在我的部分我注销这个,它返回undefined。

{{log this}}

Evidentially my context isn't being passed into my partial. 显然,我的背景并没有被传递到我的部分。

My understanding is that Handlebars supports this functionality, so what could be the reason it is not functioning? 我的理解是Handlebars支持这个功能,那么它可能不起作用的原因是什么?

STHayden is right, You need two opening braces when you call a partial STHayden是对的,当你打电话给局部时,你需要两个开口支架

{{>lifestyles this}}

This is an example of using partial templates 这是使用部分模板的示例

http://jsfiddle.net/UMBGC/16/ http://jsfiddle.net/UMBGC/16/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM