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


#1

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


#2

On 12/16/05, don mc 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


#3

Hi Don,

On 12/16/05, don mc 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


sam


#4

Sam S. wrote:

Hi Don,

On 12/16/05, don mc 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


sam

Thanks all for the quick response!
Don