javascript - Rendering dynamically generated {{link-to}} links in an Ember.js Handlebar template expression -
i have ember template rendering text handlebar expression, i.e. {{caption}}. text being rendered has hashtags in it, each of need make clickable, , going specific route in ember app.
i created helper parse text , replace each hashtag link necessary route combined hashtag, handlebar expression looks like: {{clickable-hashtags caption}}. however, helper creates links using regular html <a href> tags, , returned using ember.handlebars.safestring.
i use ember's {{#link-to}} helper method each hashtag instead, can't seem figure out how that. possible handlebars parse out link-to tags within template's {{caption}} expression?
well, computed property
the caption:
this #hashtag caption
in controller:
computedcaption: function () { var words = caption.split(" "); return words.map(function (e) { var ishashtag = e.charat(0) === "#"; return {ishashtag: ishashtag, text: e}; }); }.property("computedcaption") template:
{{#each computedcaption |cap|}} {{#if cap.ishashtag}} {{#link-to 'tags' cap.text}}{{cap.text}}{{/link-to}} {{else}} {{cap.text}} {{/if}} {{/each}} result
this #hashtag caption
Comments
Post a Comment