# Layout Question .. (Sitemesh related)

**URL:** <https://www.ruby-forum.com/t/layout-question-sitemesh-related/56541>\
**Category:** Rails\
**Created:** [March 31, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/layout-question-sitemesh-related/56541 "2006-03-31T23:56:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkhumri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/258eb7/32.png) [@mkhumri](https://www.ruby-forum.com/u/mkhumri)\
**Post date:** [March 31, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/layout-question-sitemesh-related/56541/1 "2006-03-31T23:56:12Z")

</div>

Hi,

I understand that the layout concept is very similar to OpenSymphony’s  
Sitemesh project. I have done a lot of development with Sitemesh, but am  
fairly new to Rails. I am wondering if there is a way for a layout in  
rails to find out value of a variable from a page it is decorating?

In sitemesh you would be able to do on some page being decorated and then in the layout  
page, you can access the value of show\_menu using page.getProperty(…)  
and can show or hide the menu.

Is there a way to do something like the above in Rails?  
For example a template t1.rhtml could be:

 Some content 

And this is the layout1.rhtml (layout file that t1 gets decorated with):

 \<%=@content\_for\_layout%\> 

Is this possible in rails? If yes, how?

Thanks,  
Mufaddal.

---

<div class="post-metadata">

**Author:** ![mkhumri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/258eb7/32.png) [@mkhumri](https://www.ruby-forum.com/u/mkhumri)\
**Post date:** [April 1, 2006, 1:06am UTC](https://www.ruby-forum.com/t/layout-question-sitemesh-related/56541/2 "2006-04-01T01:06:52Z")

</div>

Mufaddal K. wrote:

> Hi,
> 
> I understand that the layout concept is very similar to OpenSymphony’s  
> Sitemesh project. I have done a lot of development with Sitemesh, but am  
> fairly new to Rails. I am wondering if there is a way for a layout in  
> rails to find out value of a variable from a page it is decorating?

Yes - the content is processed before it is passed to the layout, and  
you can set instance variables (@xxx) in the content for use in the  
layout.

> ```
> <!-- can I set a variable show_menu here --> </div>
> 
> ```

\<% @show\_menu = true -%\>

(note: the - in front of the %\> prevents an empty line being written in  
the HTML)

> And this is the layout1.rhtml (layout file that t1 gets decorated with):

\<% if @show\_menu -%\>

\<% end -%\>

> \<%=@content\_for\_layout%\>

regards

Justin
