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 element associated with the respective
snipits and the 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 element) apply only to one specific html snipit of
many such snipits that share a common 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 element associated with the respective
snipits and the 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 element) apply only to one specific html snipit of
many such snipits that share a common element. I am wondering
how others are approaching this situation. Thanks for any input.

layout:


<%= yield :page_header %> <%= yield %> ---------------------------------------------------

view:


<% content_for ‘page_header’ do %>
javascript includes, stylesheet includes, raw javascript, etc.
<% end %>

blah blah

I’d also suggest having a “end_of_body” yield so you can easily insert
javascript that must go right before the closing tag.

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 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