Forum: Ruby on Rails a master layout in which other layouts are embedded?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7b2880cb9d7d75511c9b4448c016f62d?d=identicon&s=25 Marc na (marconrails)
on 2007-02-20 14:34
(Received via mailing list)
hi all

i would like to design my site so there is a master layout which is
the same for every page or a group of pages then a layout for each
controller, as scaffolds create, which gets embedded within the master
layout. then finally within this layout the actual action code is
displayed.

is this possible? what is the code to embed a layout within a layout?

thanks

marc
D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-02-20 15:21
(Received via mailing list)
- application.rhtml is the master layout that gets rendered if no
other layout is specified. inside it, you put something like this to
the place where your "subtemplate" of each controller should go in
...some HTML...
<%= yield :sublayout %>
...someHTML...
- now you have a controller named "articles", then you create a layout
"articles.rhtml" inside it you do e.g. this:

<%content_for "sublayout" do %>
<div id="sublayout">
blablabla
<%= yield %> (This puts the rendered template of the action that was
requested in here)
blablabla
<div>
<%end%>
<%= render :file "layouts/application.rhrml%> (this renders the master
layout around it)

1) rails renders the action template (e.g. "show.rhtml"),
2) puts it inside the controller's "articles.rhtml" layout, which is
saved to the content_for "sublayout"
3) "application.rhtml" is rendered, and the whole "articles.rhtml" is
oput inside it where you specified <%= yield :subtemplate %>
You may read this article about best practice for sidebars in rails,
the idea is usable for stuff like this too:

http://errtheblog.com/post/28
This topic is locked and can not be replied to.