module ActionView::Helpers::CaptureHelper

def capture(*args)



<%= @greeting %>

<%= @greeting %>


You can then use that variable anywhere else. For example:

end
"The current timestamp is #{Time.now}."
@timestamp = capture do

...and Builder (RXML) templates.

<% end %>
<%= Time.now %>
Welcome to my shiny new web page! The date and time is
<% @greeting = capture do %>

The capture method can be used in ERB templates...
==== Examples

variable. You can then use this variable anywhere in your templates or layout.
The capture method allows you to extract part of a template into a
def capture(*args)
  value = nil
  buffer = with_output_buffer { value = yield(*args) }
  if string = buffer.presence || value and string.is_a?(String)
    ERB::Util.html_escape string
  end
end