This project is archived and is in readonly mode.

#1275 ✓wontfix
Norman Clarke

Add content_exists? to ActionView::Helpers::CaptureHelper

Reported by Norman Clarke | October 26th, 2008 @ 09:54 PM | in 2.x

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 %>

Comments and changes to this ticket

  • Pratik

    Pratik January 19th, 2009 @ 08:14 PM

    • 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!

  • Norman Clarke

    Norman Clarke January 19th, 2009 @ 09:57 PM

    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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages