This project is archived and is in readonly mode.

#4537 ✓resolved
Brian Durand

Add method to get to content captured with content_for from helper methods

Reported by Brian Durand | May 5th, 2010 @ 02:30 PM | in 2.3.6

In Rails 3 the only way to get for content captured with the content_for method in a view is to call yield from within a view. However, sometimes is it useful to get to this data from within a helper (for instance to provide a default value). Calling yield from within the helper method won't work, and accessing the @_content_for variable directly is not encouraged.

Proposed solution: add a captured_content_for method so helper methods can legitimately access captured content. Add to /action_pack/lib/action_view/helpers/capture_helper.rb

  # Get content previously captured with +content_for+. This is the same as calling
  # +yield+ inside a template except that this method can be used inside helper methods.
  def captured_content_for(name)

Comments and changes to this ticket

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=""></a>