Layouts - Header Integration

Basically, a layout wraps various snipits of html body-element code with a constant-content wrapper. Accordingly, it is the layout that contains the html <head> element associated with the respective snipits and the <head> element is the same for all such snipits. I seem to be encountering a variety of cases where I would like to have specific javascript code and/or styles (which I would ordinarily place in the html <head> element) apply only to one specific html snipit of many such snipits that share a common <head> element. I am wondering how others are approaching this situation. Thanks for any input.

         ... doug

Basically, a layout wraps various snipits of html body-element code with a constant-content wrapper. Accordingly, it is the layout that contains the html <head> element associated with the respective snipits and the <head> element is the same for all such snipits. I seem to be encountering a variety of cases where I would like to have specific javascript code and/or styles (which I would ordinarily place in the html <head> element) apply only to one specific html snipit of many such snipits that share a common <head> element. I am wondering how others are approaching this situation. Thanks for any input.

layout:

layout:

--------------------------------------------------- <html> <head> <%= yield :page_header %> </head> <body> <%= yield %> </body> </html> ---------------------------------------------------

view:

--------------------------------------------------- <% content_for 'page_header' do %> javascript includes, stylesheet includes, raw javascript, etc. <% end %>

blah blah ---------------------------------------------------

Perfect. Exactly what I wanted to know. Thanks! :slight_smile:

      ... doug

I was so lucky with the answer to my first question that I thought I would press further into a related aspect that is also troubling me.

I often want to launch a JavaScript when a particular page loads. The typical way that I do this is by including an onload event handler in the opening <body> tag for the page. If the particular page in question happens to be formed by embedding a snippet of html code in a layout there may be a problem in that the body tag is typically in the layout and therefore shared with other pages similarly formed and for which I do not want to launch the JavaScript. Anyone have a good way of handling this?

Thanks.

         ... doug