views:

202

answers:

2

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

+4  A: 

What you're looking for is partials and layouts. You can define a layout as a container for your page which has global design stuff (your CSS and javascript includes, headers and footers, etc. Inside this view, you can yield to another template, and that template can render partials.

Mike Trpcic
That's true in rails, but is it true in erb when not in rails?
Wayne Conrad
No. Rails handles those methods for you. You can however look at the rails source code for ActionController, as it contains the appropriate methods, and you can either include the required module(s), or implement them yourself.
Mike Trpcic
Yeah, i know of them, but unfortunately I'm not using Rails. I'm a Sinatra person :)
Geo
+2  A: 

No, you can't inherit an erb template - it isn't a class. It is just a file.

EDIT:

According to @Dan's comment, I took a look on Django template inheritance and it looks very similar to Rails content_for. However I don't know how to use it outside of Rails. Take a look here at points 3.2 and 3.3, and here.

klew
I don't think you answered the question at all. If you've had any experience with Django templates, you'd understand what he's trying to ask.
Dan Loewenherz