Forum: Ruby on Rails Purpose of 'yield' in layout file in Flickr video?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aeac27d9f81191536d3c86ee825d71b2?d=identicon&s=25 Don Mc (dmcclean)
on 2005-12-16 18:14
During the excellent flickr video, the presenter
adds the following to the applications layout file:


<body>
  <%= yield %>
</body>



What is the purpose of the 'yield' line? I would think
there would be a content_for_layout tag there instead.

Thanks,
Don
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2005-12-16 18:21
(Received via mailing list)
On 12/16/05, don mc <don.mcclean@gmail.com> 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
5b9fe87ec1faa67a4599782930f45ec9?d=identicon&s=25 Sam Stephenson (Guest)
on 2005-12-16 18:21
(Received via mailing list)
Hi Don,

On 12/16/05, don mc <don.mcclean@gmail.com> 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/actionpac...

--
sam
Aeac27d9f81191536d3c86ee825d71b2?d=identicon&s=25 Don Mc (dmcclean)
on 2005-12-16 18:34
Sam Stephenson wrote:
> Hi Don,
>
> On 12/16/05, don mc <don.mcclean@gmail.com> 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/actionpac...
>
> --
> sam

Thanks all for the quick response!
Don
This topic is locked and can not be replied to.