require 'rubygems' require 'sinatra' require 'erb' helpers do def buffer() @_out_buf end def capture(buffer) pos = buffer.size yield buffer.slice!(pos..buffer.size) end def my_helper(&block) buffer << erb(capture(buffer, &block), :layout => :my_layout) end end template :index do <<-eos Block Helper Test <% my_helper do %>

This is the content in the block.

<% end %> eos end template :my_layout do <<-eos

This should be above the content in the block.

<%= yield %>

This should be below the content in the block.

eos end get "/" do erb :index end