How can I use views and layouts with Ruby and ERB (not Rails)?

前端 未结 4 579
闹比i
闹比i 2020-12-20 06:08

How can I use views and layouts with Ruby and ERB (not Rails)?

Today i\'m using this code to render my view:

def render(template_path, context = sel         


        
4条回答
  •  别那么骄傲
    2020-12-20 06:25

    Since you tagged it with Sinatra I assume that you us Sinatra.

    By default you view is rendered in your default layout called layout.erb

    get "/" do
       erb :index
    end
    

    This renders your view index with the default layout.

    If you need multiple layouts you can specify them.

    get "/foo" do
       erb :index, :layout => :nameofyourlayoutfile
    end
    

    * If you don't use Sinatra you may want to borrow the code from there.

提交回复
热议问题