Method: Sinatra::ContentFor#yield_content

Defined in:
lib/sinatra/content_for.rb

#yield_content(key, *args, &block) ⇒ Object

Render the captured blocks for a given key. For example:

<head>
  <title>Example</title>
  <%= yield_content :head %>
</head>

Would render everything you declared with content_for :head before closing the <head> tag.

You can also pass values to the content blocks by passing them as arguments after the key:

<%= yield_content :head, 1, 2 %>

Would pass 1 and 2 to all the blocks registered for :head.


176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/sinatra/content_for.rb', line 176

def yield_content(key, *args, &block)
  if block_given? && !content_for?(key)
    haml? && Tilt[:haml] == Tilt::HamlTemplate && respond_to?(:capture_haml) ? capture_haml(*args, &block) : yield(*args)
  else
    content = content_blocks[key.to_sym].map { |b| capture(*args, &b) }
    content.join.tap do |c|
      if block_given? && (erb? || erubi?)
        @_out_buf << c
      end
    end
  end
end