How to make a layout template in Sinatra?

后端 未结 2 501
[愿得一人]
[愿得一人] 2020-12-15 05:42

I\'m new to Sinatra and I can\'t figure out where to put my application layout.

I\'ve seen the inline method that uses

# app code    
__END__

@@lay         


        
相关标签:
2条回答
  • 2020-12-15 06:22

    If you haven't already, create a folder where your sinatra script lives called...

    views/
    

    and put your layout in there, call your layout

    layout.haml
    

    or whatever extension (e.g. .erubis) you'd like to use.

    0 讨论(0)
  • 2020-12-15 06:30

    Automatic Wrapping

    To make every view default to be wrapped in a layout, create a file in views/layout.haml and your calls to haml :myview will automatically be wrapped in this layout.

    Skipping the Layout

    If you want a particular view rendering not to use the layout, use:

    get '/' do
       # Other pages will use layout.haml, but not the main page
       haml :home, :layout => false
    end
    

    Using a Different Layout

    If you want to use a layout other than the common layout, create another file (for example views/admin_layout.haml) and then pass this as an option:

    get '/admin/create' do
       haml :create, :layout => :admin_layout
    end
    
    0 讨论(0)
提交回复
热议问题