简体   繁体   中英

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

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

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

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"}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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