diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 4710ca78..582cae52 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -268,7 +268,7 @@ module Sinatra if layout data, options[:filename], options[:line] = lookup_layout(engine, layout, views) if data - output = __send__("render_#{engine}", layout, data, options, {}) { output } + output = __send__("render_#{engine}", layout, data, options, locals) { output } end end diff --git a/test/templates_test.rb b/test/templates_test.rb index 8b815841..9cc663e1 100644 --- a/test/templates_test.rb +++ b/test/templates_test.rb @@ -85,6 +85,22 @@ class TemplatesTest < Test::Unit::TestCase assert @app.templates.empty? end + + it 'passes locals to the layout' do + mock_app { + template :my_layout do + 'Hello <%= name %>!<%= yield %>' + end + + get '/' do + erb '

content

', { :layout => :my_layout }, { :name => 'Mike'} + end + } + + get '/' + assert ok? + assert_equal 'Hello Mike!

content

', body + end end # __END__ : this is not the real end of the script.