rendering multiple views

Hi, How can i render multiple views in rails? For example i have two .rhtml files:

header.rhtml -> a chunk of html codes to be rendered on top of the page sidebar.rhtml -> also a chunk of html, to be rendered in the right side of the page

How can i call this .rhtml files from the controller and assign it to my layout? thanks!

You do this with "content_for" calls.

In your layout file, have multiple yield commands... like this;

<body>   <div id="sidebar">     <%= yield :sidebar -%>   </div>   <div id="content">     <%= yield :content -%>   </div>   <div id="footer">     <%= yield :footer -%>   </div> </body>

Then in the partial:

<% content_for :sidebar do -%>   <%= render :partial => 'sidebar' -%> <% end -%> <% content_for :footer do -%>   <%= render :partial => 'footer' -%> <% end -%> <p>This text ends up in the #Content div in the layout as it is the default</p>

Hope that helps

Mikel

oops I stuffed up on the example

<body> <div id="sidebar">    <%= yield :sidebar -%> </div> <div id="content">    <%= yield :content -%> </div> <div id="footer">    <%= yield :footer -%> </div> </body>

Should be:

<body> <div id="sidebar">    <%= yield :sidebar -%> </div> <div id="content">    <%= yield -%> </div> <div id="footer">    <%= yield :footer -%> </div> </body>

Sorry.

Mikel

So I can call the render method in the Views? Can i also have multiple render method calls in the controller methods? Thanks..

So I can call the render method in the Views?

Yes.

Can i also have multiple render method calls in the controller methods?

Never tried that, but that would not be good. Keep your view logic in the views, not in the controller.

Try it and find out. It will be a hell of a lot quicker than waiting for an answer from a mailing list. (Hint, check out the DoubleRenderError exception ).

Fred