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

js bin: http://emberjs.jsbin.com/kohubu/1/

computed properties @ emberjs


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -