2

I've been working off of Brian Mann's BackboneRails screencast, so my application structure is totally consistent with those.

The following defines the 'show' portion of a the HomepageApp Marionette Appication.

My.module('HomepageApp.Show', function(Show, App, Backbone, Marionette, $, _){

  Show.Photo = Marionette.ItemView.extend({
    tagName:'span'
  });

  Show.Photos = Marionette.CollectionView.extend({  
    template: 'homepage/show/templates/photos',

    itemView:Show.Photo,
    itemViewContainer: '#photos'
  });

  Show.Layout = Marionette.Layout.extend({
    template: 'homepage/show/templates/layout',
    regions:{
      photoRegion: '#photo-region'
    }
  });
});

I'm also overriding the Marionette.Renderer.render function with the following:

Backbone.Marionette.Renderer.render = function(template, data){
  var path = JST["backbone/apps/" + template];  

  try{
    if(!path) throw({message: "Template '" + template + "' not found!"}); 
    return path(data);
  }

  catch(err){
    console.log(err.message);
  }
}

All of my views, including many not shown here are working perfectly. The issue is that the 'template' propery of the Show.Photos CollectionView is turning up as 'undefined' in my renderer override giving me the following error:

Template 'undefined' not found!

The odd thing is that this even happens when I pass no value for the template property at all.

I also know that I'm passing it a valid Backbone collection on instantiation.

I'm totally stuck. Anyone familiar with this phenomenon?

Neil
  • 852
  • 1
  • 8
  • 14

1 Answers1

11

A CollectionView is not supposed to have a template, for this purpose you should use CompositeView, as stated in the docs:

A CompositeView extends from CollectionView to be used as a composite view for scenarios where it should represent both a branch and leaf in a tree structure, or for scenarios where a collection needs to be rendered within a wrapper template.

You can read more here: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.compositeview.md

Ingro
  • 2,841
  • 5
  • 26
  • 42