I''ve been using content_for a lot to put things in the header like extra stylesheets or javascript includes, which is great because it just appends it all and it all works nicely. I have a problem where I want to declare a content space like when I use content for: <%= yield :help %> But I want to make any content_for declarations override what was previously in there. Specifically I''m using it for help (you might have guessed :-P). I have a global generic help message, replaced in layouts with a more specific message, which in turn could be replaced by page specific help if necessary. what''s the best way of doing this? --~--~---------~--~----~------------~-------~--~----~ 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 Mar 6, 6:47 pm, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve been using content_for a lot to put things in the header like > extra stylesheets or javascript includes, which is great because it > just appends it all and it all works nicely. > > I have a problem where I want to declare a content space like when I > use content for: > > <%= yield :help %> > > But I want to make any content_for declarations override what was > previously in there. > > Specifically I''m using it for help (you might have guessed :-P). I > have a global generic help message, replaced in layouts with a more > specific message, which in turn could be replaced by page specific > help if necessary. > > what''s the best way of doing this?If I''m reading this right... you''re essentially looking for a way to set a default value for the yield and then have the ability to write over it? We do this for things like the <title> tag in the html header. # app/helpers/application_helper.rb def set_title(str="") unless str.blank? content_for :title do "#{str} »" end end end # app/views/layouts/application.html.erb <title><%= (title = yield :title) ? title : "Default title text »" %>PLANET ARGON</title> # in any view... this will set the title <% set_title ''Something different'' -%> Hope this helps! Cheers, Robby -- Robby Russell http://www.robbyonrails.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yeah that does help :-) I''m guessing that there''s no standard way of doing this then, but you''re solution looks nice. You could probably even put blocks in there if you were really keen! Thanks. On Fri, Mar 7, 2008 at 4:39 PM, Robby Russell <robbyrussell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Mar 6, 6:47 pm, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''ve been using content_for a lot to put things in the header like > > extra stylesheets or javascript includes, which is great because it > > just appends it all and it all works nicely. > > > > I have a problem where I want to declare a content space like when I > > use content for: > > > > <%= yield :help %> > > > > But I want to make any content_for declarations override what was > > previously in there. > > > > Specifically I''m using it for help (you might have guessed :-P). I > > have a global generic help message, replaced in layouts with a more > > specific message, which in turn could be replaced by page specific > > help if necessary. > > > > what''s the best way of doing this? > > If I''m reading this right... you''re essentially looking for a way to > set a default value for the yield and then have the ability to write > over it? > > We do this for things like the <title> tag in the html header. > > # app/helpers/application_helper.rb > def set_title(str="") > unless str.blank? > content_for :title do > "#{str} »" > end > end > end > > # app/views/layouts/application.html.erb > > <title><%= (title = yield :title) ? title : "Default title text > »" %>PLANET ARGON</title> > > # in any view... this will set the title > > <% set_title ''Something different'' -%> > > Hope this helps! > > Cheers, > Robby > > -- > Robby Russell > http://www.robbyonrails.com > > > > >-- Jonathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yep. One of our developers blogged about that last year. * http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up Good luck! Robby On Mar 6, 7:52 pm, "Jonathan Fantham" <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yeah that does help :-) I''m guessing that there''s no standard way of > doing this then, but you''re solution looks nice. You could probably > even put blocks in there if you were really keen! > > Thanks. > > > > On Fri, Mar 7, 2008 at 4:39 PM, Robby Russell <robbyruss...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Mar 6, 6:47 pm, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve been using content_for a lot to put things in the header like > > > extra stylesheets or javascript includes, which is great because it > > > just appends it all and it all works nicely. > > > > I have a problem where I want to declare a content space like when I > > > use content for: > > > > <%= yield :help %> > > > > But I want to make any content_for declarations override what was > > > previously in there. > > > > Specifically I''m using it for help (you might have guessed :-P). I > > > have a global generic help message, replaced in layouts with a more > > > specific message, which in turn could be replaced by page specific > > > help if necessary. > > > > what''s the best way of doing this? > > > If I''m reading this right... you''re essentially looking for a way to > > set a default value for the yield and then have the ability to write > > over it? > > > We do this for things like the <title> tag in the html header. > > > # app/helpers/application_helper.rb > > def set_title(str="") > > unless str.blank? > > content_for :title do > > "#{str} »" > > end > > end > > end > > > # app/views/layouts/application.html.erb > > > <title><%= (title = yield :title) ? title : "Default title text > > »" %>PLANET ARGON</title> > > > # in any view... this will set the title > > > <% set_title ''Something different'' -%> > > > Hope this helps! > > > Cheers, > > Robby > > > -- > > Robby Russell > > http://www.robbyonrails.com > > -- > Jonathan--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hey that''s pretty cool, did he ever consider making it into a plugin? It''d be small and simple but I''d use it! especially if he added in overwritable_content_for! :-P On Fri, Mar 7, 2008 at 5:31 PM, Robby Russell <robbyrussell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Yep. One of our developers blogged about that last year. > > * http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up > > Good luck! > > Robby > > > > On Mar 6, 7:52 pm, "Jonathan Fantham" <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > yeah that does help :-) I''m guessing that there''s no standard way of > > doing this then, but you''re solution looks nice. You could probably > > even put blocks in there if you were really keen! > > > > Thanks. > > > > > > > > > > On Fri, Mar 7, 2008 at 4:39 PM, Robby Russell <robbyruss...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Mar 6, 6:47 pm, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve been using content_for a lot to put things in the header like > > > > extra stylesheets or javascript includes, which is great because it > > > > just appends it all and it all works nicely. > > > > > > I have a problem where I want to declare a content space like when I > > > > use content for: > > > > > > <%= yield :help %> > > > > > > But I want to make any content_for declarations override what was > > > > previously in there. > > > > > > Specifically I''m using it for help (you might have guessed :-P). I > > > > have a global generic help message, replaced in layouts with a more > > > > specific message, which in turn could be replaced by page specific > > > > help if necessary. > > > > > > what''s the best way of doing this? > > > > > If I''m reading this right... you''re essentially looking for a way to > > > set a default value for the yield and then have the ability to write > > > over it? > > > > > We do this for things like the <title> tag in the html header. > > > > > # app/helpers/application_helper.rb > > > def set_title(str="") > > > unless str.blank? > > > content_for :title do > > > "#{str} »" > > > end > > > end > > > end > > > > > # app/views/layouts/application.html.erb > > > > > <title><%= (title = yield :title) ? title : "Default title text > > > »" %>PLANET ARGON</title> > > > > > # in any view... this will set the title > > > > > <% set_title ''Something different'' -%> > > > > > Hope this helps! > > > > > Cheers, > > > Robby > > > > > -- > > > Robby Russell > > > http://www.robbyonrails.com > > > > -- > > Jonathan > > > > >-- Jonathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---