I was wondering if anyone could comment on which way is better and WHY?
Here is a simplified version of what I have ( in HAML):
#header
#root
#content
= yield
#sidebar
= context_navigation
#footer
The problem:
I want #sidebar to display on some pages to show context menu, such as on the account page to show links to profile, password, order history. On the product page show links to product specifications, description, “send link”, etc. But not on other pages – such as on the home page I need to use the whole width of #root for #content to show news or featured items.
Solution & Question:
I have several ideas on how to implement it, but I was looking for some input at to which one you think is better and please explain WHY? The main objective is maintainability of code.
Here are some ideas:
- CSS \ SCSS trickery – make the sidebar a collapsible div if there context navigation is empty
- Use an else/if to load different partials depending on which part of the site I’m in.
- Create a separate layout (seems like an overkill – as I understand layouts are to be used mostly for different media such as screen vs. print vs. pdf vs. mobile – etc)
- Any other ideas?
Thank you,
Nick
You could use nested layouts to get this working:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts