Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Add content_exists? to ActionView::Helpers::CaptureHelper

#1275

This patch adds a content_exists? method to ActionView::Helpers::CaptureHelper. This can be useful for conditionally handling content set using content_for blocks.

For example:


<% if content_exists? :navigation %>
  yield :navigation
<% else %>
  <%= render :partial => "default_navigation"
<% end %>

Reported by Norman Clarke · October 26th, 2008 @ 09:54 PM

State: wontfix
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • Tag changed from actionview, capturehelper to actionview, capturehelper, patch
    • State changed from new to wontfix
    • Assigned user set to Pratik
    • Title changed from [PATCH] add content_exists? to ActionView::Helpers::CaptureHelper to Add content_exists? to ActionView::Helpers::CaptureHelper

    Missing patch. Also, using content_exists? looks like code smell. Probably you should discuss this in the mailing list, see if anyone else finds it useful.

    Thanks!

    January 19th, 2009 @ 08:14 PM

  2. Norman Clarke
    Norman Clarke

    Oops, sorry for the lack of patchiness.

    The problem is, I'm unaware of any other way to check if a named content block has been set in a content_for block other than looking for a framework-internal instance variable: @conent_for_[content_name]. The patch simply adds a wrapper method that checks for this variable in order to provide a stable API method.

    Having no sane way to check for a named content block is a pain because AFAIK it leaves you without an elegant way to provide for an overrideable default.

    I'll take it up on the list and see what people think.

    January 19th, 2009 @ 09:57 PM