Search code examples
ember.jsember-datahandlebars.jsember-cli

How do you add dynamic partial by concatenating strings in ember js?


We can add partials onto templates in ember js.

{{#each subdetail in leftSubDetails}}
   {{partial 'lists/details/link-'+subdetail}}
{{/each}}

Gives following error

Error: Parse error on line 22:
...lists/details/link-'+subdetail}}
-----------------------^
Expecting 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'INTEGER', 'BOOLEAN', 'OPEN_SEXPR', 'CLOSE_SEXPR', 'ID', 'DATA', got 'INVALID'

Solution

  • Compute the name of the partial as in the view or controller:

    partialName: function() {
        return 'lists/details/link/ + this.get('subdetail');
    }.property('subdetail')
    

    Then call it like

    {{partial partialName}}
    

    Not tested.