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
2010-03-01 00:06:36
That's true in rails, but is it true in erb when not in rails?
Wayne Conrad
2010-03-01 02:27:30
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
2010-03-01 03:02:11
Yeah, i know of them, but unfortunately I'm not using Rails. I'm a Sinatra person :)
Geo
2010-03-01 07:20:50
+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
2010-03-01 00:19:31
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
2010-09-01 01:53:45