Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. However, it gives me a null / undefined value in the helper.

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.

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.

Which seems really odd, now I'm thinking the way to send parameters to handlebars helpers might have changed in 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

<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.

like image 926
user1952811 Avatar asked Oct 20 '22 11:10

user1952811


1 Answers

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

{{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.

like image 190
Tomasz Lenarcik Avatar answered Nov 14 '22 22:11

Tomasz Lenarcik