0

I have a template I have set up as my layout using iron-router:

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

Within this layout, I have a line of html that I would like to be changed on certain routes.

My ideas is doing something like:

{{#if landing }}
<div id="page-wrapper">
{{/if}}

However, how do I implement this for a certain route? I want this variable to be true on every route except for 1.

user1072337
  • 12,615
  • 37
  • 116
  • 195

1 Answers1

0

I think that this kind of "change the template based upon what route I'm on" logic fits best into the use of a template for that route (and any others that will make this same change. Depending on the change required, you may be able to call in your base Template into the modified template. Example:

Router.route('/yourSpecialRoute', function(){ 
  this.layout('OtherLayout'); 
});

See the Layout docs - I borrowed the syntax of Setting Region Data Contexts

Having said, if you prefer not to switch layouts per route, consider setting a data on your route (something like {data: item} as shown here in the iron:route readme which can then be read by a global helper (Template.registerHelper syntax) - this will at least make it consistent across your routes / templates.

Greg Syme
  • 392
  • 3
  • 8
  • how do I make it so the template in question doesn't inherit the layout template? – user1072337 Feb 23 '16 at 05:17
  • You can override your global layout with a route of the format `Router.route('/yourSpecialRoute', function(){ this.layout('OtherLayout') });` See the [Layout docs](http://iron-meteor.github.io/iron-router/#layouts) - I borrowed the syntax of Setting Region Data Contexts. – Greg Syme Feb 23 '16 at 05:48
  • what do I put inside the function? This alone won't override the layout will it? – user1072337 Feb 23 '16 at 05:50
  • Do you have OtherLayout layout defined? I tested this against my own app which is running meteor 1.3 beta 8 and iron:router 1.0.12. – Greg Syme Feb 23 '16 at 05:57
  • Hmm, this is working, but I get the yellow error: Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction? – user1072337 Feb 23 '16 at 06:01
  • Not knowing all the intricacies of your route, I don't know what to tell you. That error does come up [here](http://stackoverflow.com/questions/26629835/meteor-v-1-0-and-ironrouter). – Greg Syme Feb 23 '16 at 06:03