Pratik Mandrekar
Pratik Mandrekar

Reputation: 9568

Ember.js - Construct a href url in handlebars template

I need to add a link that is dynamically generated in the template by appending a base url to a user id i.e I need something like 'http://google.com/?user_id=123'. How do I go about appending the base url to the user id in the href.

I need something that achieves the below result

<a href="base_url + {{user.id}}"> Visit User </a>

Upvotes: 1

Views: 6868

Answers (2)

Pratik Mandrekar
Pratik Mandrekar

Reputation: 9568

Ended up with creating a Handlebars helper

Ember.Handlebars.helper('dynamicLink', function (username, id, label) {

    var link = '<a target="_blank" href="http://xxxxxx'+
    id + '/?username=' + username +'">' + label + '</a>';
    return new Em.Handlebars.SafeString(link);
});

and then this in the templates

{{dynamicLink user.username 1 "XXXX"}}

Upvotes: 0

Michael
Michael

Reputation: 337

This problem doesn't require a Helper. You could do the following:

<a href="http://google.com/?user_id={{user.id}}"> Visit User </a>

Upvotes: 3

Related Questions