Rails check if yield :area is defined in content_for

William Yeung picture William Yeung · Oct 11, 2008 · Viewed 35k times · Source

I want to do a conditional rendering at the layout level based on the actual template has defined content_for(:an__area), any idea how to get this done?

Answer

gudleik picture gudleik · Mar 11, 2010

@content_for_whatever is deprecated. Use content_for? instead, like this:

<% if content_for?(:whatever) %>
  <div><%= yield(:whatever) %></div>
<% end %>