Forum: Ruby on Rails Access the name of the current layout from a view?

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.
82c59780911721f5cbe82d3111313519?d=identicon&s=25 Giant Cranes (giantcranes)
on 2007-05-19 19:41
Hi,

How would one access the current layout name from a view?

Thanks,
GiantCranes
82c59780911721f5cbe82d3111313519?d=identicon&s=25 Giant Cranes (giantcranes)
on 2007-05-20 08:50
Perhaps some background info would help:

I am using a dynamic layout based on a user preference. Each of these
layouts use a common html header partial which imports some css
stylesheets. I would like to do something like this in the header
partial:

<%= stylesheet_link_tag "templates/#{layout}" %>

Is this possible without passing in a layout argument to the partial?

thanks
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2007-05-21 03:39
(Received via mailing list)
You can use yield if you know there's going to be something there.
For example:

<%= stylesheet_link_tag "templates/#{yield :section_css}" %>

Then in your view, do this:

<% content_for :section_css do %>my_css_file_name<% end %>

If you really want to push this to the controller, I think you can
still set @content_for_foo so that:

@content_for_section_css = 'my_css_file_name'

should have the same effect as setting it in the view.

If you forget to set the section_css, though, you'll have a
stylesheet link to nowhere :)

On May 19, 2007, at 11:50 PM, Giant Cranes wrote:

> Is this possible without passing in a layout argument to the partial?
>
> thanks
>
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >

Steve Ross
sross@calicowebdev.com
http://www.calicowebdev.com
03d596629bdbdee047afc66cc167c5d4?d=identicon&s=25 Identry (Guest)
on 2008-04-08 20:04
(Received via mailing list)
Did you ever figure this out? I'm trying to do the same thing.

-- John

On Sun, May 20, 2007 at 2:50 AM, Giant Cranes <
rails-mailing-list@andreas-s.net> wrote:

> Is this possible without passing in a layout argument to the partial?
>
> thanks
>
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Identry, LLC
Northport, NY 11768

Phone: (631) 754-8440
Fax: (631) 980-4262
Email: jalmberg@identry.com
Member: ABA, ANA, ASDA, APS, ESA,
The Coalition Against Unsolicited Commercial Email,
Long Island Web Developer's Guild.

Visit us on the web at www.identry.com
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
BUILDING YOU A BETTER ONLINE BUSINESS
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
This topic is locked and can not be replied to.