Search code examples
templatesmeteoriron-router

Meteor - alternative layout template


I have a layout template but want to apply an alternative layout template. I have created altLayout.html but how do I apply it to my route?

Router.configure({
      layoutTemplate: 'layout',
        notFoundTemplate: 'pageNotFound',
      //waitOn: function() { return Meteor.subscribe('items'); }

    });

    Router.map(function() {
      this.route('main', {
        path: '/',
        template: 'main',
         notFoundtemplate: "pageNotFound",
         oldBrowserTemplate: "oldBrowser",
          onBeforeAction: function () {
                // render the unsupported browser page if user isn't using Chrome
                if(BrowserDetect.browser == "Chrome"){
                    layoutTemplate: 'altLayout',
                    this.render('oldBrowser');
                    this.stop();
                }
          },
      });

    });

Solution

  • The following works for me:

    Router.route("/product/:id",
    {
      name: "product_page",
      template: "product_page",
      layoutTemplate: "product_page_layout",
      data: function()
      {
        return {id: this.params.id}
      }
    });
    

    The "product_page_layout" is where your altLayout.html template goes. Basically:

    Router.map(function() {
          this.route('main', {
            path: '/',
            template: 'main',
            layoutTemplate: "altLayout",
             notFoundtemplate: "pageNotFound",
             oldBrowserTemplate: "oldBrowser",
              onBeforeAction: function () {
                    // render the unsupported browser page if user isn't using Chrome
                    if(BrowserDetect.browser == "Chrome"){
                        layoutTemplate: 'altLayout',
                        this.render('oldBrowser');
                        this.stop();
                    }
              },
          });
    
        });