Forum: Ruby on Rails Sub-layouts?

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.
114a64bf4e0cb600120f348b6447c258?d=identicon&s=25 jennyw (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Is there a way to do a sub-layout? For example, you have an application
level layout that does things like headers, footers, menus, etc. This
works great, since these things appear on every page. However, a good
number of pages require some decoration (e.g. tabs), which wrap around
the unique content (what's normally in @content_for_layout). It would be
great if you could use a tab layout that indicates that it should be
inserted into the application layout.

Is there a way to easily do this in Rails?

Thanks!

Jen
631950bd299098576e57053ce703e082?d=identicon&s=25 nshb (Guest)
on 2005-11-12 12:49
(Received via mailing list)
render :partial => 'sub_layout' will do what you are after.


Warmest regards,
Nathan.
114a64bf4e0cb600120f348b6447c258?d=identicon&s=25 jennyw (Guest)
on 2005-11-12 12:50
(Received via mailing list)
Nathaniel S. H. Brown wrote:

>render :partial => 'sub_layout' will do what you are after.
>
>
Thanks, Nathaniel. I thought of that, but couldn't think of a way to do
it that wouldn't involve calls to two partial templates (one for before,
one for after).

For example, I have an application.rhtml template that creates a top
menu and a left menu. Most of the time, the content does not include
tabs, but many pages do include tabs.  The tabs would need to wrap
around my content.

I could accomplish this with two partials. I'd call the first partial at
the beginning of my view, and the second one at the very bottom of my
view (like a header and footer). This works, but it's not the same as a
sub-layout, where I was envisioning that you could do the same thing
with a single file.  There might not be such a thing -- I just wanted to
check and see if there was some sub-layout functionality I just wasn't
aware of.

Jen
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-12 12:50
(Received via mailing list)
Assuming these templates:

page->tabs->content

I think a "render 'content'" or "render @content" tag
in the 'tabs' template would do the trick, which
itself gets assigned to page's content_for_layout. Or
perhaps it's possible to capture render content
(render_component possibly) and assign that to page's
content_for_layout.

csn


--- jennyw <jennyw@dangerousideas.com> wrote:

> one for after).
> the first partial at
> aware of.
>
> Jen
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>





__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
10d9ed7ab11115b081bb36f56a7a13bc?d=identicon&s=25 johnwilger (Guest)
on 2005-11-12 12:50
(Received via mailing list)
On 11/11/05, jennyw <jennyw@dangerousideas.com> wrote:
> I could accomplish this with two partials. I'd call the first partial at
> the beginning of my view, and the second one at the very bottom of my
> view (like a header and footer). This works, but it's not the same as a
> sub-layout, where I was envisioning that you could do the same thing
> with a single file.  There might not be such a thing -- I just wanted to
> check and see if there was some sub-layout functionality I just wasn't
> aware of.

Just did a quick test to see if I could get something working, the
code is attached.

Lets say you have 'app/views/layouts/main.rhtml' and
'app/views/layouts/sub.rhtml'. In controllers that should have the sub
layout, you can set the layout explicitly to 'sub':
114a64bf4e0cb600120f348b6447c258?d=identicon&s=25 jennyw (Guest)
on 2005-11-12 12:50
(Received via mailing list)
John Wilger wrote:

>Just did a quick test to see if I could get something working, the
>code is attached.
>
>
Lots of good ideas to think about. I think I'll eventually take up your
excercise for the reader, but probably not for this project (which is
due posthaste).

Thanks!

Jen
This topic is locked and can not be replied to.