Access the name of the current layout from a view?


#1

Hi,

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

Thanks,
GiantCranes


#2

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


#3

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 :slight_smile:

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

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

thanks


Posted via http://www.ruby-forum.com/.

Steve R.
removed_email_address@domain.invalid
http://www.calicowebdev.com


#4

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 C. <
removed_email_address@domain.invalid> 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: removed_email_address@domain.invalid
Member: ABA, ANA, ASDA, APS, ESA,
The Coalition Against Unsolicited Commercial Email,
Long Island Web D.'s Guild.

Visit us on the web at www.identry.com
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
BUILDING YOU A BETTER ONLINE BUSINESS
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>