# layout.erb
<html>
<head>
<title>My Site</title>
</head>
<body>
<%= yield %>
</body>
</html>
# index.erb
get "/tasks" do
@tasks = ["learn Ruby", "learn JavaScript"]
erb :index
end
# new.erb
get "/tasks/new" do
...
erb :new
end
ANY TIME you render a template, ie index.erb, new.erb, etc.
FIRST: the layout.erb is rendered until the yield is hit (if there is a layout.erb)
SECOND: the template you specified is rendered, for example new.erb
THIRD: you return to the layout.erb and finish loading any HTML
-
The layout allows you to have things that are common to all pages
-
for example, before the yield you might have a sweet top bar and search field you want on all pages
-
you might want a dope footer after the yield that will be loaded to every page