我在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
更多推荐
发布评论