# Content\_for\_layout

**URL:** <https://www.ruby-forum.com/t/content-for-layout/98326>\
**Category:** Rails\
**Created:** [July 13, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/content-for-layout/98326 "2006-07-13T22:10:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 13, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/content-for-layout/98326/1 "2006-07-13T22:10:55Z")

</div>

Question- if I have more then one view I wish to display in a layout ,  
how  
do I tell content\_for\_layout what to display and where ?

TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 13, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/content-for-layout/98326/2 "2006-07-13T23:00:49Z")

</div>

On Thu, 13 Jul 2006, Dark A. wrote:

> Question- if I have more then one view I wish to display in a layout , how  
> do I tell content\_for\_layout what to display and where ?

content\_for\_layout is deprecated (in favor of yield [1]), but the  
principles are the same either way. Your layout should only have one  
yield  
in it, where the content goes.

As for the rest, have your main view render one or more partials (my  
layouts typically render partials for the various pieces of the page).

[1] [Peak Obsession](http://weblog.rubyonrails.com/2006/04/25/use-params-not-params/)

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 14, 2006, 12:54am UTC](https://www.ruby-forum.com/t/content-for-layout/98326/3 "2006-07-14T00:54:19Z")

</div>

Deirdre Saoirse M. wrote on 13.07.2006 22:42:

> On Thu, 13 Jul 2006, Dark A. wrote:
> 
> > Question- if I have more then one view I wish to display in a layout , how  
> > do I tell content\_for\_layout what to display and where ?
> 
> content\_for\_layout is deprecated (in favor of yield [1]), but the

What else is deprecated? It’s really strange to say that something from  
a stable release is deprecated when it isn’t marked as deprecated and  
there is no replacement documented, isn’t it?

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 13, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/content-for-layout/98326/4 "2006-07-13T23:00:59Z")

</div>

Stuart,  
In your application.rhtml use \<%= yield %\> to display your view.  
If you wish to display another portion of that view somewhere else  
in the layout do this:

— [your view] —  
my main view content…

\<% content\_for(“nav”) do -%\>  
my nav stuff  
\<% end -%\>

— [application.rhtml] —  
\<%= yield :nav %\>

Hope this helps,  
Zack

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 14, 2006, 1:00am UTC](https://www.ruby-forum.com/t/content-for-layout/98326/5 "2006-07-14T01:00:57Z")

</div>

On Fri, 14 Jul 2006, Markus K. wrote:

> there is no replacement documented, isn’t it?  
> It is documented. Did you see the link I also pasted?

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 14, 2006, 12:35pm UTC](https://www.ruby-forum.com/t/content-for-layout/98326/6 "2006-07-14T12:35:58Z")

</div>

Yeah, I’m getting used to the sort of documentation :). It would be  
better  
perhaps if there was a page that listed all that is deprecated.  
If I’m using IRB or Scite in a straight Ruby environment that Ruby will  
tell  
it’s deprecated. Not sure how that all works in Rails and where to look  
for  
Rails generated code feedback.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 14, 2006, 12:54pm UTC](https://www.ruby-forum.com/t/content-for-layout/98326/7 "2006-07-14T12:54:42Z")

</div>

Deirdre Saoirse M. wrote on 14.07.2006 01:16:

> > there is no replacement documented, isn’t it?
> 
> It is documented. Did you see the link I also pasted?

The link? That’s a comment thread about the yield stuff but no  
documentation. The API of stable Rails is documentation and it says to  
use content\_for\_layout. The API of edge has changed and it says yield.  
So you have to say that content\_for\_layout will be deprecated in the  
future but it is the supported thing for stable Rails, isn’t it?
