Michael
Michael

Reputation: 8758

How to join a static string and a dynamic property to pass to a helper?

How can I join a static string and a dynamic property to pass to a helper?

The following does not work:

{{svg 'icon-' model.prop1}}

Thanks

Upvotes: 0

Views: 396

Answers (2)

ahmed.hoban
ahmed.hoban

Reputation: 516

This is the wrong approach. Either compute the final name of your icon in the controller or view, or create a new property in your model called icon e.g.

DS.Model.extend({
   icon: function() {
     return 'icon-' + this.get('prop1').toLowerCase();
   }.property('prop1');
  ....

controller/view:

   icon: function() {
     return 'icon-' + this.get('model.prop1').toLowerCase();
   }.property('model.prop1');

Upvotes: 1

jmurphyau
jmurphyau

Reputation: 2309

You could implement a custom helper that concatenation two values then use it as a subexpression, e.g. 'concat'

{{svg (concat 'icon-' model.prop1)}}

Upvotes: 2

Related Questions