Hi, I want to be able to have several layouts within each other so that I don''t have to keep repeating the layout code for one, in another. An example would be having a layout for the title of your web page and then having an embedded layout for the body portion in which the HTML for whatever view gets displayed. Is this possible? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060523/799832fc/attachment.html
On 5/23/06, Sam Donaldson <samonderous@gmail.com> wrote:> I want to be able to have several layouts within each other so that I don''t > have to keep repeating the layout code for one, in another. An example > would be having a layout for the title of your web page and then having an > embedded layout for the body portion in which the HTML for whatever view > gets displayed. Is this possible?Tell me if I I''m teaching you how to suck eggs, but think of layouts as containers for your views, and partials as components that you can reuse in your layouts and views. So you could create partials for each of the elements that you wish to reuse in each layout to achieve the desired result without trying to reuse layouts within layouts. cheers, Ben
I believe components are close to being deprecated. Having used them, I find them interesting in concept but suboptimal in performance. My solution has been to use partials for reusing portions a a view (and they''re cacheable!) and code in /lib for any real wiring. Anyone else know the status of components? -- View this message in context: http://www.nabble.com/adding+layouts+within+layouts-t1666558.html#a4517577 Sent from the RubyOnRails Users forum at Nabble.com.
On 5/23/06, s.ross <cwdinfo@gmail.com> wrote:> I believe components are close to being deprecated. Having used them, I find > them interesting in concept but suboptimal in performance. My solution has > been to use partials for reusing portions a a view (and they''re cacheable!) > and code in /lib for any real wiring. > > Anyone else know the status of components?I should have been more careful with my words. I wasn''t referring to rails ''components'', but was using the english word component to describe a ''partial''. I think we''re on the same wavelength about using ''partials'' as reusable portions in ''views'' and ''layouts''. cheers, Ben
Ben and Kaz Askins wrote:> On 5/23/06, s.ross <cwdinfo@gmail.com> wrote: >> I believe components are close to being deprecated. Having used them, I find >> them interesting in concept but suboptimal in performance. My solution has >> been to use partials for reusing portions a a view (and they''re cacheable!) >> and code in /lib for any real wiring. >> >> Anyone else know the status of components? > > I should have been more careful with my words. I wasn''t referring to > rails ''components'', but was using the english word component to > describe a ''partial''. I think we''re on the same wavelength about > using ''partials'' as reusable portions in ''views'' and ''layouts''. > > cheers, > Ben> This is test posting for Ruby on Rails-- Posted via http://www.ruby-forum.com/.
Hi Sam, I hope I understand your problem, but being quite new to Rails I was more than a little unsure about how to efficiently organize views and layouts in the beginning. I am still would like to read about exactly what best practices are, but what helped me a lot was discovering the "collect" mechanism. With this, you can, in your views, collect content for multiple parts in your layouts(left colum, right column, and the like), and then specify in the layouts where the that content should go. Applied to your example (title and body), this would look somewhat like this: In your views: ... <% content_for(''title'') do %> <%= render :partial => ''title'' %> <% end %> ... <% content_for(''body'') do %> <%= render :partial => ''body'' %> <% end %> ... In your layouts: ... <title><%= @content_for_title %></title> ... <body><%= @content_for_body %></body> ... Hope this helps, Ingo -- Posted via http://www.ruby-forum.com/.
On Mon, May 22, 2006 at 07:45:43PM -0700, Sam Donaldson wrote:> Hi, > > I want to be able to have several layouts within each other so that I don''t > have to keep repeating the layout code for one, in another. An example > would be having a layout for the title of your web page and then having an > embedded layout for the body portion in which the HTML for whatever view > gets displayed. Is this possible?I ran into this badly in a project that is almost finished. I have 5 major sections to the site, each with a submenu above the content which is shared for that section, save for the "current" page being highlighted. What I need is two layouts. The main layout would be: <html> <head>...</head> <body> <div id="header">...</div> <div id="left-junk">...</div> <div id="content-area"><%= @content_for_layout %></div> <div id="footer">...</div> </body> </html> But @content_for_layout would be the output of another layout: <div id="submenu">...</div> <div id="content"><%= @content_for_layout %></div> That way, each section could get its own submenu layout file, and nothing would be repeated. As it is right now, I have repeated the submenu code in all of the views for a particular section, which is hideous. My other option is to create a separate layout for each one, but then the rest of the page code would be repeated. And the last option is to create two partials for each section: a "header" and a "footer". Then I could render those in every view. That''s ugly, though, as the code would be split up. I need to be able to nest layouts, and I believe this would be a very useful feature. I just don''t have the internals experience to pull it off. Any ideas? Thanks, Michael -- Michael Darrin Chaney mdchaney@michaelchaney.com http://www.michaelchaney.com/
I couldn''t agree more. Maybe this is possible but just don''t know how to go about doing this. I thought of all of your alternatives too but they just seemed ugly. Thanks. On 5/23/06, Michael Chaney <mdchaney@michaelchaney.com> wrote:> > On Mon, May 22, 2006 at 07:45:43PM -0700, Sam Donaldson wrote: > > Hi, > > > > I want to be able to have several layouts within each other so that I > don''t > > have to keep repeating the layout code for one, in another. An example > > would be having a layout for the title of your web page and then having > an > > embedded layout for the body portion in which the HTML for whatever view > > gets displayed. Is this possible? > > I ran into this badly in a project that is almost finished. I have 5 > major sections to the site, each with a submenu above the content which > is shared for that section, save for the "current" page being > highlighted. > > What I need is two layouts. The main layout would be: > > <html> > <head>...</head> > <body> > <div id="header">...</div> > <div id="left-junk">...</div> > <div id="content-area"><%= @content_for_layout %></div> > <div id="footer">...</div> > </body> > </html> > > But @content_for_layout would be the output of another layout: > > <div id="submenu">...</div> > <div id="content"><%= @content_for_layout %></div> > > That way, each section could get its own submenu layout file, and > nothing would be repeated. > > As it is right now, I have repeated the submenu code in all of the > views for a particular section, which is hideous. > > My other option is to create a separate layout for each one, but then > the rest of the page code would be repeated. > > And the last option is to create two partials for each section: a > "header" and a "footer". Then I could render those in every view. > That''s ugly, though, as the code would be split up. > > I need to be able to nest layouts, and I believe this would be a very > useful feature. I just don''t have the internals experience to pull it > off. > > Any ideas? > > Thanks, > Michael > -- > Michael Darrin Chaney > mdchaney@michaelchaney.com > http://www.michaelchaney.com/ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060524/60355833/attachment.html
Hi! On May 23, 2006, at 7:17 PM, Sam Donaldson wrote:> I couldn''t agree more. Maybe this is possible but just don''t know > how to go about doing this. I thought of all of your alternatives > too but they just seemed ugly. > > Thanks. > > > On 5/23/06, Michael Chaney <mdchaney@michaelchaney.com> wrote: > On Mon, May 22, 2006 at 07:45:43PM -0700, Sam Donaldson wrote: > > Hi, > > > > I want to be able to have several layouts within each other so > that I don''t > > have to keep repeating the layout code for one, in another. An > example > > would be having a layout for the title of your web page and then > having an > > embedded layout for the body portion in which the HTML for > whatever view > > gets displayed. Is this possible? > > I ran into this badly in a project that is almost finished. I have 5 > major sections to the site, each with a submenu above the content > which > is shared for that section, save for the "current" page being > highlighted. > > What I need is two layouts. The main layout would be: > > <html> > <head>...</head> > <body> > <div id="header">...</div> > <div id="left-junk">...</div> > <div id="content-area"><%= @content_for_layout %></div> > <div id="footer">...</div> > </body> > </html> > > But @content_for_layout would be the output of another layout: > > <div id="submenu">...</div> > <div id="content"><%= @content_for_layout %></div> > > That way, each section could get its own submenu layout file, and > nothing would be repeated. > > As it is right now, I have repeated the submenu code in all of the > views for a particular section, which is hideous. > > My other option is to create a separate layout for each one, but then > the rest of the page code would be repeated. > > And the last option is to create two partials for each section: a > "header" and a "footer". Then I could render those in every view. > That''s ugly, though, as the code would be split up. > > I need to be able to nest layouts, and I believe this would be a very > useful feature. I just don''t have the internals experience to pull it > off. > > Any ideas? > > Thanks, > MichaelHave you seen the content_for method? You can use it to push content up to the layout from a normal view. Like so: # in the layout: <html> <body> <div id=''header></div> <div id=''content''><%= @content_for_layout %></div> <div id=''sidebar''><%= yield :sidebar %></div> <div id=''footer''></div> </body> </html> # in any normal view file that gets rendered in the above layout <% content_for :sidebar do %> <h1>I''m content for the sidebar!</h1> <% end %> # other view code. This allows you to make placeholders in your layout that get populated from the content_for method in your view files. -Ezra -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060524/d5eca82e/attachment.html
Ok where the hell did you pick _that_ one up EZ? I even missed it before now... On 5/23/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:> > Have you seen the content_for method? You can use it to push content up to > the layout from a normal view. Like so: > > > # in the layout: > <html> > <body> > <div id=''header></div> > <div id=''content''><%= @content_for_layout %></div> > <div id=''sidebar''><%= yield :sidebar %></div> > <div id=''footer''></div> > </body> > </html> > > > # in any normal view file that gets rendered in the above layout > > <% content_for :sidebar do %> > <h1>I''m content for the sidebar!</h1> > <% end %> > > # other view code. > > > This allows you to make placeholders in your layout that get populated > from the content_for method in your view files. > > > -Ezra > > > > > > > > > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060602/ba894137/attachment.html
Sorry to dredge up an old thread, but I''m retrofitting some older code. I have a helper: def title_for_page raise "Site name not set" if !SITE_NAME # make a lot of noise if no site name "<title>#{SITE_NAME}#{" : #{@page_title}" if @page_title}</title>" end The intent of this code is to use the site name as the initial part of the title, then optionally a colon separator and the page name. I''d prefer to write (in layout.rhtml): <title><%= yield :page_title %></title> Any suggestions for implementing the conditional inclusion of the colon? TIA -- View this message in context: http://www.nabble.com/adding-layouts-within-layouts-t1666558.html#a4777092 Sent from the RubyOnRails Users forum at Nabble.com.
Add a global helper...? On 6/8/06, s.ross <cwdinfo@gmail.com> wrote:> > > Sorry to dredge up an old thread, but I''m retrofitting some older code. I > have a helper: > > def title_for_page > raise "Site name not set" if !SITE_NAME # make a lot of noise if no > site > name > "<title>#{SITE_NAME}#{" : #{@page_title}" if @page_title}</title>" > end > > The intent of this code is to use the site name as the initial part of the > title, then optionally a colon separator and the page name. I''d prefer to > write (in layout.rhtml): > > <title><%= yield :page_title %></title> > > Any suggestions for implementing the conditional inclusion of the colon? > > TIA > -- > View this message in context: > http://www.nabble.com/adding-layouts-within-layouts-t1666558.html#a4777092 > Sent from the RubyOnRails Users forum at Nabble.com. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060619/b94e2857/attachment.html