# rendering multiple views

**URL:** <https://discuss.rubyonrails.org/t/rendering-multiple-views/31447>\
**Category:** rubyonrails-talk\
**Created:** [July 5, 2008, 3:04am UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447 "2008-07-05T03:04:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan\_bayona](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@ryan\_bayona](https://discuss.rubyonrails.org/u/ryan_bayona)\
**Post date:** [July 5, 2008, 3:04am UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447/1 "2008-07-05T03:04:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Mikel1](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@Mikel1](https://discuss.rubyonrails.org/u/Mikel1)\
**Post date:** [July 5, 2008, 6:45am UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447/2 "2008-07-05T06:45:57Z")

</div>

You do this with "content\_for" calls.

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

\<body\> &nbsp;&nbsp;\<div id="sidebar"\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= yield :sidebar -%\> &nbsp;&nbsp;\</div\> &nbsp;&nbsp;\<div id="content"\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= yield :content -%\> &nbsp;&nbsp;\</div\> &nbsp;&nbsp;\<div id="footer"\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= yield :footer -%\> &nbsp;&nbsp;\</div\> \</body\>

Then in the partial:

\<% content\_for :sidebar do -%\> &nbsp;&nbsp;\<%= render :partial =\> 'sidebar' -%\> \<% end -%\> \<% content\_for :footer do -%\> &nbsp;&nbsp;\<%= 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

---

<div class="post-metadata">

**Author:** ![Mikel1](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@Mikel1](https://discuss.rubyonrails.org/u/Mikel1)\
**Post date:** [July 5, 2008, 6:46am UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447/3 "2008-07-05T06:46:56Z")

</div>

oops I stuffed up on the example

> \<body\> \<div id="sidebar"\> &nbsp;&nbsp;&nbsp;\<%= yield :sidebar -%\> \</div\> \<div id="content"\> &nbsp;&nbsp;&nbsp;\<%= yield :content -%\> \</div\> \<div id="footer"\> &nbsp;&nbsp;&nbsp;\<%= yield :footer -%\> \</div\> \</body\>

Should be:

\<body\> \<div id="sidebar"\> &nbsp;&nbsp;&nbsp;\<%= yield :sidebar -%\> \</div\> \<div id="content"\> &nbsp;&nbsp;&nbsp;\<%= yield -%\> \</div\> \<div id="footer"\> &nbsp;&nbsp;&nbsp;\<%= yield :footer -%\> \</div\> \</body\>

Sorry.

Mikel

---

<div class="post-metadata">

**Author:** ![ryan\_bayona](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@ryan\_bayona](https://discuss.rubyonrails.org/u/ryan_bayona)\
**Post date:** [July 5, 2008, 9:34am UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447/4 "2008-07-05T09:34:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mikel1](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@Mikel1](https://discuss.rubyonrails.org/u/Mikel1)\
**Post date:** [July 5, 2008, 12:51pm UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447/5 "2008-07-05T12:51:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [July 5, 2008, 1:50pm UTC](https://discuss.rubyonrails.org/t/rendering-multiple-views/31447/6 "2008-07-05T13:50:09Z")

</div>

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
