title: Don't show div surrounding a yield if nothing calls it
body: <p>I have this snippet in a layout:</p>
  
  <pre><code>    &lt;div class="yui-g" style="min-width: 760px"&gt;    
        &lt;!-- top row --&gt;  
          &lt;%= yield :top_row %&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>If nothing calls <code>content_for :top_row</code> then i'm left with a styled, empty rectangle on the page.  The right thing to do would be restyle the layout (and the whole site tbh) but that's not an option right now (legacy debt and more pressing requirements).  Is there a way to wrap the div in some code that checks if the yield is actually yielding to anything, and to not render it if so?</p>
  
  <p>cheers, max</p>
  
  <p>EDIT - this is a rails 2.2.2 project btw.</p>
  
  <p>EDIT 2</p>
  
  <p>@arnep suggested the following, which works: </p>
  
  <pre><code>&lt;% content = yield :top_row %&gt;
  &lt;% unless content.blank? %&gt;
    &lt;div class="yui-g" style="min-width: 760px"&gt;   
      &lt;%= content %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>What i'd like to do next is to wrap that up in a helper which i can use like so:</p>
  
  <pre><code>&lt;% yield_if(:top_row) do |content| %&gt;
    &lt;div class="yui-g" style="min-width: 760px"&gt;   
        &lt;%= content %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;    
  </code></pre>
  
  <p>I'm struggling with that helper though, since it involves yielding in the block passed to the method AND yielding to the content in :top_row.  Here's what i tried, which doesn't work - it renders the whole page into the returned string.  I think i've got it backwards somehow.</p>
  
  <pre><code>def yield_if(content_name, &amp;block)
    content = yield content_name 
    if content.blank?  
      ""
    else
      yield content 
    end
  end 
  </code></pre>