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.
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