Marcos R. Guevara Marcos R. Guevara -4 years ago 172
CoffeeScript Question

Choose between two templates render with Marionette

I use Marionette (Backbone.js) on my Rails app.

What i want to do is load another template if matches an id, this is what i have

join_room.html.slim file

tmpltRoute: templateRoute

@MyAppManager.module "Layout", (Layout, MyAppManager, Backbone, Marionette, $, _) ->
Layout.MenuView = Marionette.ItemView.extend
initialize: (options)->
@isPremium = options.isPremium
@isStandard = options.isStandard
@tmpltRoute = options.tmpltRoute
template: JST[this.tmpltRoute]

Answer Source

You can override getTemplate on your ItemView to achieve this (see docs)

getTemplate: function(){
    if (this.model.get("foo")){
      return JST[foo];
    } else {
      return JST[bar];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download