Dale very kindly sent me an example project yesterday which showed how I use a popdown javascript calendar form callable from within my rhtml page. Apologies to Dale for showing some of his code here. I noticed something separate which works but confused me a little as to how. Basically it''s this: scaffold.rhtml <html> <head> <link href="/stylesheets/scaffold.css" rel="stylesheet" type="text/css" /> <% if @use_calendar %> <%= render "layouts/calendar" %> <% end %> <head> <body> <%= @content_for_layout %> </body> </html> edit.rhtml top of this file there is the line: <% @use_calendar = true %> Now I would have thought this would generate HTML which would effectively have the contents scaffold.rhtml but with the contents of edit.rhtml replacing the line <%= @content_for_layout %>. Which would mean the <% @use_calendar = true %> line would fall into the body section, the <% if @use_calendar %><%= render "layouts/calendar" %><% end %> in the head section - BEFORE the <% @use_calendar = true %> line. Am I misunderstanding how this works, or if not why does this all work (ie. the layouts/calendar get rendered?) Glenn Confused as usual
Glenn Smith wrote:>Now I would have thought this would generate HTML which would >effectively have the contents scaffold.rhtml but with the contents of >edit.rhtml replacing the line <%= @content_for_layout %>. > >Which would mean the <% @use_calendar = true %> line would fall into >the body section, the ><% if @use_calendar %><%= render "layouts/calendar" %><% end %> >in the head section - BEFORE the <% @use_calendar = true %> line. > >Am I misunderstanding how this works, or if not why does this all work >(ie. the layouts/calendar get rendered?) > >I believe rendering in the presence of layouts works like this: - render the template normally with side-effects (e.g. @use_calendar is set) - store the output into @content_for_layout - now render the layout (which can access all instance variables as usual, @use_calendar and @content_for_layout being amongst them) Another common "trick", is to use a @page_title variable in your layout that can be defined individually in templates. Sebastian