# Access the name of the current layout from a view?

**URL:** <https://www.ruby-forum.com/t/access-the-name-of-the-current-layout-from-a-view/104573>\
**Category:** Rails\
**Created:** [May 19, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/access-the-name-of-the-current-layout-from-a-view/104573 "2007-05-19T19:41:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [May 19, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/access-the-name-of-the-current-layout-from-a-view/104573/1 "2007-05-19T19:41:05Z")

</div>

Hi,

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

Thanks,  
GiantCranes

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [May 20, 2007, 8:50am UTC](https://www.ruby-forum.com/t/access-the-name-of-the-current-layout-from-a-view/104573/2 "2007-05-20T08:50:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [May 21, 2007, 3:39am UTC](https://www.ruby-forum.com/t/access-the-name-of-the-current-layout-from-a-view/104573/3 "2007-05-21T03:39:53Z")

</div>

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 C. wrote:

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

Steve R.  
removed\_email\_address@domain.invalid  
[http://www.calicowebdev.com](http://www.calicowebdev.com)

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [April 8, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/access-the-name-of-the-current-layout-from-a-view/104573/4 "2008-04-08T20:04:29Z")

</div>

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/](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](http://www.identry.com)  
\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>  
BUILDING YOU A BETTER ONLINE BUSINESS  
\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>\<\>
