Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I inherit an erb template?

Is there any way to have a template inherit another template? I'm not using Rails.

like image 435
Geo Avatar asked Feb 28 '10 10:02

Geo


1 Answers

I also really like the django template inheritance, but it's not available at least with sinatra.

The sinatra book explains how you can use a layout.erb to define a standard page layout:

You just need to define a views/layout.erbfile with something like:

<html>
  <head>..</head>
  <body>
    <%= yield %>
  </body>
</html>

And then call your erb template with erb :index for example. Sinatra will render both templates and include the contents of your index template inside the result of the layout.erb rendering.

like image 132
simao Avatar answered Sep 29 '22 21:09

simao