0

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

Michael
  • 8,357
  • 20
  • 58
  • 86

2 Answers2

2

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

{{svg (concat 'icon-' model.prop1)}}
jmurphyau
  • 2,309
  • 13
  • 11
1

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');
ahmed.hoban
  • 516
  • 3
  • 10