# Purpose of 'yield' in layout file in Flickr video?

**URL:** <https://www.ruby-forum.com/t/purpose-of-yield-in-layout-file-in-flickr-video/50473>\
**Category:** Rails\
**Created:** [December 16, 2005, 6:14pm UTC](https://www.ruby-forum.com/t/purpose-of-yield-in-layout-file-in-flickr-video/50473 "2005-12-16T18:14:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [December 16, 2005, 6:14pm UTC](https://www.ruby-forum.com/t/purpose-of-yield-in-layout-file-in-flickr-video/50473/1 "2005-12-16T18:14:19Z")

</div>

During the excellent flickr video, the presenter  
adds the following to the applications layout file:

 \<%= yield %\>

What is the purpose of the ‘yield’ line? I would think  
there would be a content\_for\_layout tag there instead.

Thanks,  
Don

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [December 16, 2005, 6:21pm UTC](https://www.ruby-forum.com/t/purpose-of-yield-in-layout-file-in-flickr-video/50473/2 "2005-12-16T18:21:56Z")

</div>

On 12/16/05, don mc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What is the purpose of the ‘yield’ line? I would think  
> there would be a content\_for\_layout tag there instead.
> 
> Thanks,  
> Don

It has to do with the way the layouts are built. Yield is just a  
shortcut. You can also do:

\<%= yield :foo %\> instead of @content\_for\_foo.

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [December 16, 2005, 6:21pm UTC](https://www.ruby-forum.com/t/purpose-of-yield-in-layout-file-in-flickr-video/50473/3 "2005-12-16T18:21:56Z")

</div>

Hi Don,

On 12/16/05, don mc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What is the purpose of the ‘yield’ line? I would think  
> there would be a content\_for\_layout tag there instead.

You can say \<%= yield %\> instead of \<%= @content\_for\_layout %\> and,  
e.g., \<%= yield :sidebar %\> instead of \<%= @content\_for\_sidebar %\>.

Here’s the relevant magic:  
[http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action\_view/base.rb?rev=3314#L292](http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_view/base.rb?rev=3314#L292)

–  
sam

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [December 16, 2005, 6:34pm UTC](https://www.ruby-forum.com/t/purpose-of-yield-in-layout-file-in-flickr-video/50473/4 "2005-12-16T18:34:42Z")

</div>

Sam S. wrote:

> Hi Don,
> 
> On 12/16/05, don mc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > What is the purpose of the ‘yield’ line? I would think  
> > there would be a content\_for\_layout tag there instead.
> 
> You can say \<%= yield %\> instead of \<%= @content\_for\_layout %\> and,  
> e.g., \<%= yield :sidebar %\> instead of \<%= @content\_for\_sidebar %\>.
> 
> Here’s the relevant magic:  
> [http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action\_view/base.rb?rev=3314#L292](http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_view/base.rb?rev=3314#L292)
> 
> –  
> sam

Thanks all for the quick response!  
Don
