为什么Template.body.helper数据对于子模板不可见?(Why Template.body.helper data is not visible to a child template?

编程入门 行业动态 更新时间:2024-10-26 03:26:48
为什么Template.body.helper数据对于子模板不可见?(Why Template.body.helper data is not visible to a child template?)

我在main.html中有几个模板,如下所示。 我意识到Template.body.helper({aglobal:return aGlobal})在父模板(如下面的navbarTemplate)中不可见。 当我在父模板中定义“aglobal”助手函数时,我可以在没有问题的情况下在HTML中访问它。 这里有什么问题?

<body> {{>navbarTemplate}} {{>editingUsers}} <div class="container"> <div class="row"> <div class="col-md-6"> <p>Editor</p> {{>editor}} </div> <div class="col-md-6"> <p>Viewer</p> {{>viewer}} </div> </div> </div> </body>

I have several templates in my main.html as depicted below. I realised that Template.body.helper({aglobal: return aGlobal}) is not visible in parent templates (like navbarTemplate below). When I define the "aglobal" helper fucntion inside a parent template I can access it in the HTML without a problem. What is the problem here?

<body> {{>navbarTemplate}} {{>editingUsers}} <div class="container"> <div class="row"> <div class="col-md-6"> <p>Editor</p> {{>editor}} </div> <div class="col-md-6"> <p>Viewer</p> {{>viewer}} </div> </div> </div> </body>

最满意答案

您可以使用函数Template.parentData(n)如下所示: Template parentdata官方文档

@Giova.panasiti That wasn't the exact answer that I was looking for but I find the answer in the doc you shared, thanks.

The answer seems to be very simple; "Helpers on Template.body are only available in the tags of your app. To register a global helper, use Template.registerHelper." -- http://blazejs.org/api/templates.html#Template-body

更多推荐

本文发布于:2023-07-04 11:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   数据   body   helper   Template

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!