0

I have a meteorjs default layout file and i am routing to different pages using iron-route, What i am trying to do is not show navigation on the home page. I can do this by using two separate files but i want to do this with single file.

<template name="layout">

    <head>
        <title>
            {{title}}
        </title>
    </head>
    <body>

        {{> navigation }}

        <div class="nav_padding">
            {{> yield}}
        </div>


        {{> footer}}

    </body>

    </template>

My route

    Router.route('/', function(){
        this.layout('homeLayout');
        this.render('home', {
            data:{title: 'some'}
        });
    });
4

1 回答 1

2

There are a few ways you can do this, but here's a simple solution...

Add a helper to your layout template which indicates if the nav should be shown based on the route name:

Template.myLayout.helpers({
  showNav: function() {
    return Router.current().route.getName() !== 'home';
  }
});

Modify your template to conditionally show the navigation template:

<template name="myLayout">
  {{#if showNav}}
    {{> navigation }}
  {{/if}}
  <div class="nav_padding">
    {{> yield}}
  </div>
  {{> footer}}
</template>

In order for your route to be named you may need to modify your route to something like this:

Router.route('/', {
  name: 'home',
  template: 'home',
  layoutTemplate: 'myLayout',
  data: {title: 'some'}
});
于 2015-05-04T22:55:07.423 回答