I need to add various header and footer dressings around groups of form fields for GUI goodness, and am wondering if there''s already something out there that will suit my needs. These headers/footers have special properties for display(title, help links, etc...). I want to be able to easily take advantage of the existing HTML helper methods provided for controllers, in a mini-layout type way. Header/Footer dressing: <table> <tr><td class="Title"><%=@title%></td></tr> <tr> <td> <%=@content_for_dressing%> </td> </tr> </table> Controller rhtml: ...some display stuff... <%DRESS%> <%=text_field(''project'', ''name'')%> ... <%ME%> ...some other display stuff... Basically so that anything between DRESS and ME becomes the content for this mini-layout. Ideally the header/footer dressing would be able to somehow be a class so that the properties for it could be set in the layout, and then displayed. Of course it doesn''t have to be exactly this way. Hopefully I''ve described what I''m looking to do, well enough that someone has some possible avenues that I can persue. Thanks, Steve
> I want to be able to easily take > advantage of the existing HTML helper methods provided for > controllers, in a > mini-layout type way. > > Header/Footer dressing: > <table> > <tr><td class="Title"><%=@title%></td></tr> > <tr> > <td> > <%=@content_for_dressing%> > </td> > </tr> > </table>That HTML''s kind of overkill, no? Why not just this: /shared/header.rhtml: <h1><%= @title %></h1> /your/file.rhtml: <%= @title = "Foo" %> <%= render "shared/header" %> <%= @content_for_dressing %> ...and format with css. See "using sub templates in ActionView::Base docs.
> That HTML''s kind of overkill, no? Why not just this: > > /shared/header.rhtml: > <h1><%= @title %></h1> > > /your/file.rhtml: > <%= @title = "Foo" %> > <%= render "shared/header" %> > <%= @content_for_dressing %> > > ...and format with css. > > See "using sub templates in ActionView::Base docs.Yes, that HTML was quite overkill. I just typed it out for a quick example to illustrate what I was looking to do(not how I actually write my XHTML w/CSS). I have seen the documentation about sub-templates, and that is almost what I want. I just want to be able to abstract that away somehow so that the header/footer are always included, and that the content between two places, is what gets placed in between the header/footer. I''m not sure, but is something along these lines possible? <%fd = FormDresser.new("Some title") fd.content = "%> content, and formatting goes here. <%" fd.render%> Maybe not by splitting the string delimiters, but somehow? Thanks, Steve
Sorry Steve, maybe I''m missing something, but why don''t you just use partials? In main.rhtml file: <%= render_partial "main_table", @some_table_data %> <%= render_partial "another_table", @another_table $> Then in _main_table.rhtml and _another_table.rhtml: <%= render_partial "standard_table_header" %> ... do stuff with content here ... <%= render_partial "standard_table_header" %> The "content" of the table could be in a significantly different format in each of the @some_table_data and @another_table objects. Or if they''re both going to respond to the same methods, you could just use render_collection_of_partials. Does that get you to where you need to be? Cheers, bs. On Apr 6, 2005 11:56 AM, Steve V <ruby-ChEX1j9zMF7JbC0vcoRRxNBPR1lH4CV8@public.gmane.org> wrote:> > That HTML''s kind of overkill, no? Why not just this: > > > > /shared/header.rhtml: > > <h1><%= @title %></h1> > > > > /your/file.rhtml: > > <%= @title = "Foo" %> > > <%= render "shared/header" %> > > <%= @content_for_dressing %> > > > > ...and format with css. > > > > See "using sub templates in ActionView::Base docs. > > Yes, that HTML was quite overkill. I just typed it out for a quick example > to illustrate what I was looking to do(not how I actually write my XHTML > w/CSS). > > I have seen the documentation about sub-templates, and that is almost what I > want. I just want to be able to abstract that away somehow so that the > header/footer are always included, and that the content between two places, > is what gets placed in between the header/footer. > > I''m not sure, but is something along these lines possible? > > <%fd = FormDresser.new("Some title") > fd.content = "%> > content, and formatting goes here. > <%" > fd.render%> > > Maybe not by splitting the string delimiters, but somehow? > > Thanks, > Steve > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
> Yes, that HTML was quite overkill. I just typed it out for a quick example > to illustrate what I was looking to do(not how I actually write my XHTML > w/CSS).I find it funny that you referred to it as a quick example. But let''s not get into that :)> I have seen the documentation about sub-templates, and that is almost what I > want. I just want to be able to abstract that away somehow so that the > header/footer are always included, and that the content between two places, > is what gets placed in between the header/footer. > > I''m not sure, but is something along these lines possible? > > <%fd = FormDresser.new("Some title") > fd.content = "%> > content, and formatting goes here. > <%" > fd.render%> > > Maybe not by splitting the string delimiters, but somehow?Try the capture method: http://rails.rubyonrails.com/classes/ActionView/Helpers/CaptureHelper.html <% @greeting = capture do %> Welcome To my shiny new web page! <% end %> Ruby blocks are cool... -- rick http://techno-weenie.net
> I find it funny that you referred to it as a quick example. But let''s > not get into that :)Shhh. :) I was err... trying to accommodate those that have not yet seen the light of XHTML+CSS.> Try the capture method: > http://rails.rubyonrails.com/classes/ActionView/Helpers/CaptureHelper.html > > <% @greeting = capture do %> > Welcome To my shiny new web page! > <% end %> > > Ruby blocks are cool...Indeed they are. That pretty much did what I was looking for. One of these days I''m going to go through and read the whole API. I''ve slowly been reading bits and pieces of it. Apparently they have thought of everything though for Rails. Thanks, Steve
> Sorry Steve, maybe I''m missing something, but why don''t you just > use partials? > > In main.rhtml file: > > <%= render_partial "main_table", @some_table_data %> > <%= render_partial "another_table", @another_table $> > > Then in _main_table.rhtml and _another_table.rhtml: > > <%= render_partial "standard_table_header" %> > ... do stuff with content here ... > <%= render_partial "standard_table_header" %> > > The "content" of the table could be in a significantly different > format in each of the @some_table_data and @another_table objects. Or > if they''re both going to respond to the same methods, you could just > use render_collection_of_partials. > > Does that get you to where you need to be?That gets me close. I was looking for a way to do everything in a class or module based fashion, since some of the values need to be manipulated before being placed in the template. Thanks, Steve