What you want is called a "layout"; just put a file called layout.haml (or layout.erb or using the template language of your choice) in your view directory, and by default the contents of other views will be wrapped in it. Place the yield output in the layout where the contents of the individual views should be displayed. For instance:
- Haml:
= yield - Erb:
<%= yield %>
If you want the result of using the route to be used in another layout, you can specify the name of an alternative layout type as follows:
get "/login" do # ... haml :login, :layout => :logged_out # Or for ERb: # erb :login, :layout => :logged_out end
If you want a specific route not to use any layout, go through false :
get "/" do # ... haml :home, :layout => false # Or for ERb: # erb :home, :layout => false end
See the Sinatra book for more details.
source share