Nested ERB template layouts like Liquid?
With Liquid, you can nest layouts. E.g., my site's default layout builds off of the base layout.
Is this possible with ERB? If so, how?
I'm asking because I'm migrati开发者_开发知识库ng a GitHub Pages site to Sinatra, so that I can handle forms natively (not with Wufoo or Google Forms).
try this:
make a file called layout.haml (or erb or whatever your templates are in), and put it in the views folder. this is your site layout, and it could look like this (I'm using haml):
%html
%head
%link(rel="stylesheet" type="text/css" href="style.css")
%body
%div.outer
%div.inner
= yield
the magic part is the =yield
this is where Sinatra will render whatever template you call in your route. the = tells your template to expect ruby code.
for example, if your route is
get '/' do
haml :index
end
then your template at /views/index.haml will be inserted. you can also use a custom layout if you tell your template to override the one at /views/layout.haml.
hope this helps.
精彩评论