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

application.html.erb is a file that applies to all views in rails. In a sense, its main file is that all child files are styled / structured after.

How can I use this with Sinatra?

+4
source share
2 answers

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.

+5
source

Yes! This is the layout file located in /views/layout.erb. You must create it yourself or use this script to create the skeleton of the sinatra application.

0
source

Source: https://habr.com/ru/post/1337836/


All Articles