Specify template for component based on property

Let’s say I have the following data:

    "type": "video",
    "url": "http://videos.com/2346",
    "title": "Awesome video!",
    "description": "An awesome video",
    "embed_url": "http://videos.com/v/2346.mp4"
    "type": "photo",
    "url": "http://photos.com/2346",
    "title": "Awesome photo!",
    "description": "An awesome photo",
    "embed_url": "http://photo.com/p/2346.jpeg"

And I want to display it in the following template:

{{#each item in model}}
    {{embedded-object item=item}}

How can I setup the embedded-object component such that it will display a <video> element if the type property is video, and an <img> element if the type is photo?

One idea I had was to create computed properties on the component:

    isVideo: function() {
        return this.get('type') == 'video';
    isPhoto: function() {
        return this.get('type') == 'photo';
    isRich: function() {
        return this.get('type') == 'rich';
    isLink: function() {
        return this.get('type') == 'link';

And then in the embedded-object component:

{{#if isVideo}}
  {{embed-video item=item}}
{{#if isPhoto}}
  {{embed-photo item=item}}
{{#if isRich}}
  {{embed-rich item=item}}
{{#if isLink}}
  {{embed-link item=item}}

But this doesn’t feel like it’s the correct thing to do. Any ideas?

It depends how much custom logic you want for each of the individual embedded components, and how you want your html to look. One option if there’s not much logic is to have a switch statement based on the type which returns a template name that you can render with the handlebars partial helper. If you need more custom logic per type you can instead return components from that helper and render them with the handlebars view helper. You can see both options @ http://emberjs.jsbin.com/bacavoka/2/edit.

I’ve done something similar for a view, so I assume a component would work similarly. The trick is to define the templateName property on the view, like this:

SomeView = Ember.View.extend({
  templateName: function(){
    return 'embedded-types/' + this.get('type');

If the type data are loaded asynchronously (or if the items change type), you may have to add an observer and do something like this in your view/component:

_templateChanged: function(){