views:

88

answers:

3

What are the implications of calling yield() twice? For example

- if yield :content_header
   yield :content_header
- else
  No Content Header

Is this going to eat up little bits of time? I can't seem to get content_for? to work :/

A: 

I believe this will run everything in the content_for block twice, which doesn't make much sense.

Is there any reason you can't handle the conditional logic inside the content_for?:

<% content_for :content_header do %>
  <% if some_condition %>
    <%= render_some_important_thing %>
  <% else %>
    <%= render_absence_of_thing %>
   <% end %>
<% end %>
zetetic
+1  A: 

Maybe you'd like a default value for your content if none is supplied?

Ryan Bates does something like this in his code (www.railscasts.com):

<title><%= h(yield(:title) || "Untitled") %></title>

which yields a given title or "Untitled" if none was provided. Also give some of these a shot.

DJTripleThreat
A: 

Calling yield twice results in the block being evaluated in the current scope twice.

Toby Hede