Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a custom directory for layouts in Sinatra?

Tags:

layout

sinatra

I have a Sinatra app with multiple layouts. I want to isolate them into their own subdirectory in views:

app.rb
views/
views/layouts/
views/layouts/default.haml
views/layouts/print.haml
views/layouts/mobile.haml

This works, except that I have to explicitly set a layout with each render call:

get '/' do
    haml :index, {:layout => :'layouts/default'}
end

Is there a way to set the layout globally (for all routes within a module, for example), or to tell Sinatra where look for layouts outside of default directory?

like image 442
Arman H Avatar asked Aug 18 '13 19:08

Arman H


1 Answers

Need to RTFM better... So there is no specific option for Sinatra itself, but you can set a default layout for each rendering engine, e.g. HAML:

configure do
  set :haml, :layout => :'layouts/default'
end
like image 122
Arman H Avatar answered Sep 30 '22 08:09

Arman H