* A site has the default global layout and navigation links. * Within the site, it has several different sections, * each section has many pages, which has same sub nav links and some common parts. * how do i wrap a section page with section layout first, and then global layout? * what''s the best way to handle such multi level layout situation? Two solutions I tried, and I don''t like either one. 1. create a layout for each section, the layout duplicate global layout elements 2. only use global layout, then render partial section_header, section_footer on every single page. thanks. thanks. Dorren --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What I do a lot is to have a /app/views/common directory if you run render :partial => "/common/confirm_button" it would render the file /app/views/common/_confirm_button.rhmtl. but equally, I don''t know your layout, but a "global.rhtml" layout, which calls "render :partial => "section_links"" would render "_section_links.rhtml" in the appropriate directory. so in the users controller it''ll render /users/_section_links.rhtml and in the product controller it does /product/_section_links.rhtml. maybe that''s what you want. Dorren wrote:> * A site has the default global layout and navigation links. > * Within the site, it has several different sections, > * each section has many pages, which has same sub nav links and some > common parts. > > * how do i wrap a section page with section layout first, and then > global layout? > * what''s the best way to handle such multi level layout situation? > > > Two solutions I tried, and I don''t like either one. > 1. create a layout for each section, the layout duplicate global > layout elements > 2. only use global layout, then render partial section_header, > section_footer on every single page. > > thanks. > > thanks. > Dorren-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> but a "global.rhtml" layout, > which calls "render :partial => "section_links"" > > would render "_section_links.rhtml" > in the appropriate directory. > > so in the users controller it''ll render /users/_section_links.rhtml > and in the product controller it does /product/_section_links.rhtml. > > maybe that''s what you want.This will work if all sections are very similar, and require every section to have section_links.rhtml, which should be ok in most situations. through trial and error, i found out this setup is more flexible. To use namespace in layout file, and rename layout as partial. so I copy layouts/application.rhtml to shared/layouts/ _application.rhtml ======== shared/layouts/_application.rhtml ============<html> <head> ..... <body> <%= render(:partial => "/shared/global_header") %> <div id="section_header"><%= yield "top" %></div> <div id="main"><%= yield %></div> <%= render(:partial => "/shared/global_footer") %> </body> </html> ======== layouts/product.rhtml ============<% content_for :top do %> product_home | hardware | software | ... <% end %> <%= render(:partial => "/shared/layouts/application") %> ======== layouts/support.rhtml ============<%= render(:partial => "/shared/layouts/application") %> Product section wants a section navbar on top, so it just do that in the product layout, for ProductController Support section don''t need navbar, so it just skips it. one drawback, namespaced part can not be cached. Dorren --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-10 12:43 UTC
Re: how to do multi level layout
I hope my question is consistant with your thread. I have a VERY large application with all kinds of sub-applications such as forums, diggs, blogs, etc. and wish to split up the \application\app metaphor to be \application\app\subprogram. Has anyone done this? I see following your thread how you''d handle calling views, but what about models and controllers? I am grateful for any reply. Thanks, Kathy On Jul 9, 9:37 am, Dorren <dorrenc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > but a "global.rhtml" layout, > > which calls "render :partial => "section_links"" > > > would render "_section_links.rhtml" > > in the appropriate directory. > > > so in the users controller it''ll render /users/_section_links.rhtml > > and in the product controller it does /product/_section_links.rhtml. > > > maybe that''s what you want. > > This will work if all sections are very similar, and require every > section to have section_links.rhtml, which should be ok in most > situations. > > through trial and error, i found out this setup is more flexible. To > use namespace in layout file, and rename layout as partial. > so I copy layouts/application.rhtml to shared/layouts/ > _application.rhtml > > ======== shared/layouts/_application.rhtml ============> <html> > <head> > ..... > <body> > <%= render(:partial => "/shared/global_header") %> > <div id="section_header"><%= yield "top" %></div> > > <div id="main"><%= yield %></div> > > <%= render(:partial => "/shared/global_footer") %> > </body> > </html> > > ======== layouts/product.rhtml ============> <% content_for :top do %> > product_home | hardware | software | ... > <% end %> > > <%= render(:partial => "/shared/layouts/application") %> > > ======== layouts/support.rhtml ============> <%= render(:partial => "/shared/layouts/application") %> > > Product section wants a section navbar on top, so it just do that in > the product layout, for ProductController > Support section don''t need navbar, so it just skips it. > > one drawback, namespaced part can not be cached. > > Dorren--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7/7/07, Dorren <dorrenchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > * A site has the default global layout and navigation links. > * Within the site, it has several different sections, > * each section has many pages, which has same sub nav links and some > common parts.This PDF from a rails conf presentation has some interesting ideas: http://culann.com/slides/Static_Site_Railsconf_2007_final.pdf --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I ran into a similar problem and came across the following discussion about "nested layouts" which provides some good insight into the matter: http://errtheblog.com/post/28 it seems there''s also a nested-layout plugin available which I haven''t had any experience with.. Mike On 7/9/07, Dorren <dorrenchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > but a "global.rhtml" layout, > > which calls "render :partial => "section_links"" > > > > would render "_section_links.rhtml" > > in the appropriate directory. > > > > so in the users controller it''ll render /users/_section_links.rhtml > > and in the product controller it does /product/_section_links.rhtml. > > > > maybe that''s what you want. > > This will work if all sections are very similar, and require every > section to have section_links.rhtml, which should be ok in most > situations. > > > through trial and error, i found out this setup is more flexible. To > use namespace in layout file, and rename layout as partial. > so I copy layouts/application.rhtml to shared/layouts/ > _application.rhtml > > ======== shared/layouts/_application.rhtml ============> <html> > <head> > ..... > <body> > <%= render(:partial => "/shared/global_header") %> > <div id="section_header"><%= yield "top" %></div> > > <div id="main"><%= yield %></div> > > <%= render(:partial => "/shared/global_footer") %> > </body> > </html> > > > ======== layouts/product.rhtml ============> <% content_for :top do %> > product_home | hardware | software | ... > <% end %> > > <%= render(:partial => "/shared/layouts/application") %> > > > > ======== layouts/support.rhtml ============> <%= render(:partial => "/shared/layouts/application") %> > > > Product section wants a section navbar on top, so it just do that in > the product layout, for ProductController > Support section don''t need navbar, so it just skips it. > > one drawback, namespaced part can not be cached. > > Dorren > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Some good ideas in this presentation but if I understand the OP''s question, it''s about having multiple tiers of layout. Sort of like (tags omitted for brevity): <!-- layout.erb --> <html> <!-- xhtml''ey stuff --> <%= render :partial => yield :section_layout %> </html> <!-- _my_section_layout.erb --> <div> Hi! Welcome to the chunky bacon section </div> <%= yield :layout %> <div> goodbye to the chunky bacon section </div> <!-- my_view.erb --> <% content_for :section_layout do %>my_section_layout<% end %> <p> Other stuff specific to the particular view. Note that the section layout can also be set in the controller using @content_for_section_layout. </p> I''m not positive this works, and you might have to "help" Rails understand the search path for the section layouts, but it''s worth a try. On Jul 10, 2007, at 9:53 AM, Luis wrote:> > On 7/7/07, Dorren <dorrenchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> * A site has the default global layout and navigation links. >> * Within the site, it has several different sections, >> * each section has many pages, which has same sub nav links and some >> common parts. > > This PDF from a rails conf presentation has some interesting ideas: > http://culann.com/slides/Static_Site_Railsconf_2007_final.pdf > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
perhaps I''m misunderstanding but why not this: http://agilewebdevelopment.com/plugins/nested_layouts chau! Tim On Jul 7, 8:40 pm, Dorren <dorrenc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> * A site has the default global layout and navigation links. > * Within the site, it has several different sections, > * each section has many pages, which has same sub nav links and some > common parts. > > * how do i wrap a section page with section layout first, and then > global layout? > * what''s the best way to handle such multi level layout situation? > > Two solutions I tried, and I don''t like either one. > 1. create a layout for each section, the layout duplicate global > layout elements > 2. only use global layout, then render partial section_header, > section_footer on every single page. > > thanks. > > thanks. > Dorren--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---