Search code examples
meteoriron-router

Override layout template in iron-router Meteor


I have a meteor app using iron router for navigation. I have a layout file that renders on every page. Although there's a page where I don't want the layout file to be displayed/rendered. I bet there exists an elegant way to achieve so but unfortunately I haven't found so yet.

Router.configure({
    layoutTemplate: 'layout',
    loadingTemplate: 'loading',
    notFoundTemplate: 'notapage'
});
Router.route('dataNotFound', function() {
    this.render('notapage');
});
Router.route('test/qwerty', function() {
    this.render('abc');
}, {

name: 'abc',
waitOn: function() {
    return [
        Meteor.subscribe('testSubscription')
    ];
}

});

Layout file :

<template name="layout">
<nav class="navbar navbar-default navbar-fixed-top">
    ...
</nav>
    <div class="clearfix"></div>
    <div class="page-container">
        {{>yield}}
    </div>
<div class="page-footer">
    ...
</div>

If the route equals abc, I dont want the layout.html file to be rendered/displayed.


Solution

  • You can override the default layout file on an individual Route definition, see: http://iron-meteor.github.io/iron-router/#layouts

    Router.route('/post/:_id', function () {
       this.layout('ApplicationLayout');
    });
    

    The documentation also describes how to render templates into different yield regions in the same layout template.