Ball, Donald A Jr \(Library\)
2007-Apr-18 19:25 UTC
best practice for modifying html header in templates
In my rails app, I have a few resources whose header needs differ from the rest of the resources - they need extra javascript libraries, or different css stylesheets, or link to an RSS feed to which I''d also like to link in the html header. All pages share a standard layout template, of course. I''m wondering what the best practice is for adding extra stuff to the html header for individual pages. Currently, I populate @extra_javascripts and @extra_stylesheets variables in the page templates that require extra love, and check for the existence of those variables in the master layout and add the links as necessary. I could do this again for my rss feed, but this strikes me as a bit smelly. Has anyone tackled a better approach to this? - donald --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Apr-18 20:09 UTC
Re: best practice for modifying html header in templates
> In my rails app, I have a few resources whose header needs differ from > the rest of the resources - they need extra javascript libraries, or > different css stylesheets, or link to an RSS feed to which I''d also like > to link in the html header. All pages share a standard layout template, > of course. I''m wondering what the best practice is for adding extra > stuff to the html header for individual pages. Currently, I populate > @extra_javascripts and @extra_stylesheets variables in the page > templates that require extra love, and check for the existence of those > variables in the master layout and add the links as necessary. I could > do this again for my rss feed, but this strikes me as a bit smelly. Has > anyone tackled a better approach to this?In your views do something like this: <% content_for("page_header") do -%> <%= javascript_include_tag ''my_special_js'' %> .... <% end -%> Then in your layout do this: ... <head> ... <%= yield "page_header" %> ... </head> We do this and it works quite well. Another nice one is "page_ending_javascript" for those odd cases where the javascript has to go at the end of the page just before the closing </body>. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ball, Donald A Jr \(Library\)
2007-Apr-18 20:18 UTC
Re: best practice for modifying html header in templates
> In your views do something like this: > > <% content_for("page_header") do -%> > <%= javascript_include_tag ''my_special_js'' %> > .... > <% end -%> > > Then in your layout do this: > > ... > <head> > ... > <%= yield "page_header" %> > ... > </head>That''s _exactly_ the elegant solution I was hoping existed. Many thanks. - donald --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jodi Showers
2007-Apr-19 00:12 UTC
Re: best practice for modifying html header in templates
On 18-Apr-07, at 4:18 PM, Ball, Donald A Jr ((Library)) wrote:> >> In your views do something like this: >> >> <% content_for("page_header") do -%> >> <%= javascript_include_tag ''my_special_js'' %> >> .... >> <% end -%> >> >> Then in your layout do this: >> >> ... >> <head> >> ... >> <%= yield "page_header" %> >> ... >> </head> > > That''s _exactly_ the elegant solution I was hoping existed. Many > thanks. > > - donald >That''s a really cool solution Philip. Learn something new very other day. thanx. Jodi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---