My first post on this blog was Explicit layouts for Sinatra.
There was a post (Rendering different layouts with Sinatra) a few days ago on GITTR that uses a similar technique, though they use one method per specific layout – it looks a cleaner than what I did, though if you have dozens of different layouts (probably not likely) you might want to go with passing the layout name as a param as I did.
I simplified my code and it now looks like the GITTR example:
def erb_special(template, layout, options={}) erb template, options.merge(:layout => 'layouts/special') end get '/special/?' do erb_special :'special/index' end
