简体   繁体   English

为什么Meteor模板助手不在上下文中返回变量?

[英]Why does Meteor template helper not return variable in context?

For some reason, this doesn't work at all. 出于某种原因,这根本不起作用。

{{user_slugged username}}

The {{username}} is a variable available to the template. {{username}}是模板可用的变量。 However, it gives me a null / undefined value in the helper. 但是,它在助手中给出了一个null / undefined值。

Here is my helper code 这是我的帮手代码

UI.registerHelper('user_slugged', function(username) {

... other stuff... return things.


}

The issue I am having is when I try something like this {{user_slugged 'Hello'}} it does everything right and returns what is expected. 我遇到的问题是当我尝试这样的事情{{user_slugged 'Hello'}}它会做正确的事并返回预期的内容。

However, when I try {{user_slugged username}} it doesn't seem to work even though I can easily display {{username}} in that same line of code. 但是,当我尝试{{user_slugged username}} ,即使我可以在同一行代码中轻松显示{{username}} ,它似乎也无法正常工作。

Which seems really odd, now I'm thinking the way to send parameters to handlebars helpers might have changed in Meteor 0.8.0 . 这看起来很奇怪,现在我想在Meteor 0.8.0发送参数给车把助手的方式可能已经改变了。 If so, it'd be great if someone could point me into the right direction or give me an answer to this question. 如果是这样,如果有人能指出我正确的方向或给我一个问题的答案,那就太棒了。

EDIT: To clarify I am able to use {{username}} in the same line as {{user_slugged username}} so something like this works 编辑:澄清我能够在{{user_slugged username}}的同一行使用{{username}} ,所以像这样的工作

<a href="{{user_slugged username}}">{{username}}</a>

username is an object property that is available in the template and at the point where I am trying to send it in as a param to the helper. username是一个对象属性,可以在模板中以及我尝试将其作为参数发送给帮助程序的位置。

I am not sure why this is happening (maybe there is a global helper username ?), but you should be able to fix it easily by writing 我不确定为什么会这样(也许有一个全球帮助username ?),但你应该能够通过写作轻松解决它

{{user_slugged ./username}}

instead of 代替

{{user_slugged username}}

The dot always means the current data context, so there is no way that the rendering engine will get confused about it. 点始终表示当前数据上下文,因此渲染引擎无法对其产生混淆。

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

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