In your code sample you are trying to connect templateName
property to controller.model.Name
this approach works for the first time as you also said but templateName
property is used by the ember view for first time only. i.e. if templateName
changes after the view is rendered it does not re-render the view. And if you want your approach to work you will need to re-render the view each time your dependent properties changes.
//sample
App.ViewGoesHereView = Ember.View.extend({
templateName: function(){
var templateName = 'baseTemplate';
var value = this.get('controller.model.Name');
if (Ember.compare(value, 'abc') === 0) {
templateName = 'abcTemplate';
return templateName;
}
else if (Ember.compare(value, 'xyz') === 0) {
templateName = 'xyzTemplate';
return templateName;
}
return templateName;
}.property('controller.model.Name'),
//new property to re-render the view
reRenderView: function () {
this.rerender();
}.observes('controller.model.Name')
});
NOTE: I haven't tested this code since I didn't had the full use case of your scenario. Please do revert back if this dosen't works.