content_given

Created: 2008-10-14 03:42
Updated: 2016-12-15 09:22
License: mit

README.markdown

ContentGiven

Adds a very small helper to your views for determining if content_for :foo was used.

This means you don't always have to render the containing markup around yield :foo.

Example

Before content_given:

<!-- In app/views/layouts/application.html.erb %>
<html>
  <body>
    <div id="sidebar">
      <%= yield :sidebar
    </div>
    
    <div id="content">
      <%= yield %>
    </div>
  </body>
</html>

<div id="sidebar"> is always rendered.

After content_given:

<!-- In app/views/layouts/application.html.erb %>
<html>
  <body>
    <% if content_given? :sidebar %>
      <div id="sidebar">
        <%= yield :sidebar
      </div>
    <% end %>
    
    <div id="content">
      <%= yield %>
    </div>
  </body>
</html>

<div id="sidebar"> is only rendered if you used content_for :sidebar

Copyright

Copyright (c) 2008 Josh Nichols, released under the MIT license

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more