class Middleman::TemplateContext

def wrap_layout(layout_name, &block)

Returns:
  • (void) -

Parameters:
  • layout_name (String, Symbol) --
def wrap_layout(layout_name, &block)
  # Save current buffer for later
  buf_was = save_buffer
  # Find a layout for this file
  layout_file = ::Middleman::TemplateRenderer.locate_layout(@app, layout_name, current_engine)
  # Get the layout engine
  extension = File.extname(layout_file[:relative_path])
  engine = extension[1..-1].to_sym
  # Store last engine for later (could be inside nested renders)
  self.current_engine = engine
  engine_was = current_engine
  # By default, no content is captured
  content = ''
  # Attempt to capture HTML from block
  begin
    content = capture_html(&block) if block_given?
  ensure
    # Reset stored buffer, regardless of success
    restore_buffer(buf_was)
  end
  # Render the layout, with the contents of the block inside.
  concat_safe_content render_file(layout_file, @locs, @opts) { content }
ensure
  # Reset engine back to template's value, regardless of success
  self.current_engine = engine_was
end