NullVoxPopuli
NullVoxPopuli

Reputation: 65083

What is the Sinatra Equivelant of the Rails application.html.erb?

the application.html.erb is a file that is applied to all views in rails. In a way, its the master file, that all child files are styled / structured after.

How can I use this with Sinatra?

Upvotes: 4

Views: 1818

Answers (2)

Phrogz
Phrogz

Reputation: 303136

What you want is called a "layout"; simply put a file named layout.haml (or layout.erb, or using the templating language of your choice) in your views directory and by default the contents of other views will be wrapped in it. Put the output of yield in the layout where the contents of individual views should go. For example:

  • Haml: = yield
  • Erb: <%= yield %>

If you want the result of a route to use a different layout, you can specify the name of the alternative layout view like so:

get "/login" do
   # ...
   haml :login, :layout => :logged_out

   # Or for ERb:
   # erb :login, :layout => :logged_out
end

If you want a particular route to not use any layout, pass false:

get "/" do
   # ...
   haml :home, :layout => false

   # Or for ERb:
   # erb :home, :layout => false
end

For more, see the Sinatra book.

Upvotes: 5

hkairi
hkairi

Reputation: 385

yeah ! it's the layout file located in /views/layout.erb You should create it by your self or use this script to generate a sinatra application's skeleton.

Upvotes: 0

Related Questions