Layouts work very well if I want to do this: [Header stuff] <%= @content_for_layout %> [Footer stuff] but what I''d like to do is something like this: [Page header stuff] [Column A header stuff] <%= @content_for_column_a %> [Column A footer stuff] [Column B header stuff] <%= @content_for_column_b %> [Column B footer stuff] [Page footer stuff] Is there a neat way to do this? (It could be done with render calls, but that means I''m including headers and footers all over the place, and isn''t very DRY.) Cheers, Pete Yandell
Yep you can do pretty much just what you are doing in this code. Try this:> [Page header stuff] > [Column A header stuff] > <%= @content_for_aheader %> > [Column A footer stuff] > [Column B header stuff] > <%= @content_for_bheader %> > [Column B footer stuff] > [Page footer stuff]And in your controller set: @aheader and @bheader and they will be placed in the layout. The content_for_varname syntax works for any var not just the layout. HTH- -Ezra On Oct 11, 2005, at 10:03 PM, Pete Yandell wrote:> Layouts work very well if I want to do this: > > [Header stuff] > <%= @content_for_layout %> > [Footer stuff] > > but what I''d like to do is something like this: > > [Page header stuff] > [Column A header stuff] > <%= @content_for_column_a %> > [Column A footer stuff] > [Column B header stuff] > <%= @content_for_column_b %> > [Column B footer stuff] > [Page footer stuff] > > Is there a neat way to do this? (It could be done with render > calls, but that means I''m including headers and footers all over > the place, and isn''t very DRY.) > > Cheers, > > Pete Yandell > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org 509-577-7732
Well, you can always do this: <table> <tr> <td> [Column A header stuff] </td> <td> [Column B header stuff] </td> </tr> <tr> <%= @content_for_column_a_and_b_which_includes_td_statements %> </tr> <tr> <td> [Column A footer stuff] </td> <td> [Column B footer stuff] </td> </tr> </table> Pete Yandell wrote:> Layouts work very well if I want to do this: > > [Header stuff] > <%= @content_for_layout %> > [Footer stuff] > > but what I''d like to do is something like this: > > [Page header stuff] > [Column A header stuff] > <%= @content_for_column_a %> > [Column A footer stuff] > [Column B header stuff] > <%= @content_for_column_b %> > [Column B footer stuff] > [Page footer stuff] > > Is there a neat way to do this? (It could be done with render calls, > but that means I''m including headers and footers all over the place, > and isn''t very DRY.) >
On 12.10.2005, at 8.59, Ezra Zygmuntowicz wrote:> Yep you can do pretty much just what you are doing in this code. > Try this: > > >> [Page header stuff] >> [Column A header stuff] >> <%= @content_for_aheader %> >> [Column A footer stuff] >> [Column B header stuff] >> <%= @content_for_bheader %> >> [Column B footer stuff] >> [Page footer stuff] >> > > And in your controller set: @aheader and @bheader and they will be > placed in the layout. The content_for_varname syntax works for any > var not just the layout.Or, when you probably have a lot of html in what you want to pass, do this in your normal views: <% content_for("aheader") do %> Stuff to the first column <% end %> <% content_for("bheader") do %> Stuff to the second column <% end %> You can do whatever you want to inside the content_for blocks. Whatever is the output will be passed to the layout and you can use it just like Ezra described. See the api docs [1] for the capture mechanism for more info. //jarkko [1] http://rails.rubyonrails.com/classes/ActionView/Helpers/ CaptureHelper.html -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Pete Yandell wrote:> Layouts work very well if I want to do this: > > [Header stuff] > <%= @content_for_layout %> > [Footer stuff] > > but what I''d like to do is something like this: > > [Page header stuff] > [Column A header stuff] > <%= @content_for_column_a %> > [Column A footer stuff] > [Column B header stuff] > <%= @content_for_column_b %> > [Column B footer stuff] > [Page footer stuff] > > Is there a neat way to do this? (It could be done with render calls, > but that means I''m including headers and footers all over the place, > and isn''t very DRY.)I recently had exactly that problem, and ended up nesting column B inside column A. Conceptually it worked, because I was building a left-to-right hierarchical menu interface, but it would be less of a good idea if the columns were independent. -- Alex
Thanks, Jarkko. That''s exactly what I was looking for. (I figured Rails had to have this one covered...I just couldn''t find it.) On 12/10/2005, at 4:42 PM, Jarkko Laine wrote:> <% content_for("aheader") do %> > Stuff to the first column > <% end %> > > <% content_for("bheader") do %> > Stuff to the second column > <% end %>_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails