Omkommersind
Omkommersind

Reputation: 295

How to pass object to handlebars helper

Using handlebars-1.1.2 and old emberjs 1.5.1. I've code:

{{#each queue in appController.queues_services_array}}
    <label for="{{GetObjectId queue}}">{{queue.title}}</label></div>
{{/each}}

and helper:

Handlebars.registerHelper('GetObjectId', function(value) {
  return value.id;
});

The problem is that data given to helper is just string "queue", not an object. I wonder how can I pass object "queue" to helper.

Upvotes: 1

Views: 526

Answers (1)

Jon Koops
Jon Koops

Reputation: 9261

You can use the bind-attr helper to bind your value to a specific attribute:

<label {{bind-attr for=queue.id}}>{{queue.title}}</label>

Or alternatively if you do not expect the value to change it is possible to use the unbound helper, which yields some improved performance:

<label for="{{unbound queue.id}}">{{queue.title}}</label>

The best thing you could do would be to update to a newer version of Ember so you could make use of the newer syntax which allows you to use regular Handlebars:

<label for="{{queue.id}}">{{queue.title}}</label>

Assuming you have the time and budget.

Upvotes: 3

Related Questions