Advices for main layout definition


#1

Hi,
I’m making my first application with Meteor and I’m a little bit confused about how to define the HTML main layout of the application. Like a lot of application I will have a sidebar on the left with a list of entity. And a click on one of them will load it on the main section. You cannot access this part of the application if you are not logged (so no need to handle a not logged sidebar). I am using the iron:router plugin.

So my question is : What is the best solution for defining the main layout?

Do I have to make a default layout template that I pass to the router as a default layout and call the good templates for the different yield parts (sidebar and center if needed)
Or do I have to write my default layout in the main.html and call here the template to render the sidebar (as it will be always here) and use the route for only the center part?

Sorry for the dummy question but maybe you will have a tuto to read (another ^^) or maybe the solution is obvious… Or maybe I didn’t describe sufficiently my layout to make a decision.

Thanks for the tips! :wink:


#2

Yes - http://iron-meteor.github.io/iron-router/#layouts

You don’t have to use the yield helper for sidebars if the sidebar template doesn’t change according to the current route

The main.html file isn’t required


#3

OK thanks Reoh!

For the sidebar, it’s not going to change but it have to be loaded from a collection.
I put a template on the default layout and directly in a JS for the template I put:

Template.body.helpers({ tasks() { return Tasks.find({}); }, });

?

Or there is a way to achieve that with iron:router?

Thanks for this last advice :stuck_out_tongue:


#4

Is that the data for the non-changing sidebars or the content for a certain route?


#5

Hi Ralof!
The «tasks» are the data for the sidebar. It’s not going to change between 2 routes but it can change between users and along the time… like a list of channel for a chat app…


#6

You can just put it in the sidebar:

Template.sidebar.helpers

#7

OK :ok_hand:
I will put a template named sidebar and the defaultLayout and put the collection.find on a helper of the sidebar template!
Thanks!