Maintaining existing templates while using iron:router's yield


#1

I’m new to Meteor but I’m loving it so far!

Currently I built a nav template and now I’m integrating iron:router. My main.html looks like this:

<body>
 	{{> nav}}

 	{{> yield}}
</body>

What is happening is that my nav is not showing (only the yield) and I want my Nav to show (with the route’s template appearing below the nav).

I’d move my nav template to the head, but {{> loginButtons}} does not render in the head…


#2

Remove the template injection from within the body tags.

<body>

</body>

<template name="myCoolTemplate">
    {{ >nav}}

    {{ >yield}}
</template>

Meteor will inject into the body tag for you.

http://docs.meteor.com/#/full/livehtmltemplates

When your app is loaded, it automatically renders the special template called

, which is written using the element instead of a . You insert a template inside another template by using the {{> inclusion}} operator.

#3

Thank you!

Does this mean that I have to include the {{> nav}} inside every single template I create if I want the nav to show? Not that big of a deal, just trying to follow DRY principals.


#4

I use something like this:

<body>

</body>
<template name="main_layout">
    {{ >nav}}

    {{ >yield}}
</template>

The first project I did just had all the nav HTML in the main template with {{ >yield}} where the primary content area would go (was a basic bootstrap with top-nav-bar dealio).

You obviously need to set the layout template in iron router

Router.configure({ layoutTemplate: 'main_layout'});

EDIT:
so, as you traverse to other routes and get new templates rendered they will be injected into {{>yield}} in your main_layout, and nav will be there (and not get rerendered)