3
\$\begingroup\$

I'm making a Backbone-Marionette app with a file structure that matches restful verbs as much as possible. It looks something like this:

+ backbone
  + apps
    + student
      + show
      + list
      + new
    + lesson
      + show
      + new
      + edit

If, for example, the student show controller wanted to display a lesson, I simply execute a command that sends which lesson I want and the region in which it should be inserted like so:

App.execute( "show:lesson", lesson, someRegion );

This has mostly worked well, but now I need to create an email preview that contains a lesson. This representation of lesson show shouldn't look exactly like the existing lessons show - for example, it doesn't need edit and delete links.

What I'm doing now is adding a config object to my command above that looks like this...

App.execute( "show:lesson", lesson, someRegion, { template: "email" } );

... then I unpack that object in my Marionette controller and set it on the model. Now that it's piggy backed on the model, I use it to conditionally get the correct template in my view like so:

Show.Lesson = Backbone.Marionette.ItemView.extend({
  getTemplate: function() {
    if( this.model.get( "config" ).template === "email" ) {
      return "lessons/show/lesson_email";
    } else {
      return "lessons/show/lesson";
    }
  }
}); 

This feels a little weird to me, plus it doesn't quite work when getting templates for Marionette.CompositeViews. Should I be making completely new Marionette views for these email preview versions of my resource representations? Would it make more sense for my file structure to look like this?

+ backbone
  + apps
    + lesson
      + show
      + show_email
      + new
      + edit
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.