# Newbie question about rendering partials and rhtml

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361>\
**Category:** Rails\
**Created:** [May 4, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361 "2007-05-04T19:12:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 4, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/1 "2007-05-04T19:12:03Z")

</div>

Hi,

im not sure if i am on the right path here, so i figured i would ask.

Basically, all of my pages have the same header and footer, and i was  
wondering if there was some way i could reference this from the rhtml  
file?

from what i have read on partial and template rendering, this is done in  
the  
controller, but in my case, the header and footer are static, so there  
is no  
logic. Basically, I am just trying to minimize the number of places i  
need  
to edit in case i make a change to my header or footer (i.e. if i add a  
link, i would really like to just update 1 file, rather than do it in  
all of  
my views).

## Is this possible? thanks!

View this message in context:  
[http://www.nabble.com/newbie-question-about-rendering-partials-and-rhtml-tf3692733.html#a10324965](http://www.nabble.com/newbie-question-about-rendering-partials-and-rhtml-tf3692733.html#a10324965)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 4, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/2 "2007-05-04T19:19:05Z")

</div>

Have a look at layouts, that is precisely what they are for. For  
example, if  
you create an html skeleton, call it application.rhtml and place it in  
the  
layouts folder (in views/), the app will call it by default. In the area  
where you want the controller-generated output to go, simply place this  
call:

\<% yield %\>

and the magic will take place.

On 5/4/07, gmoniey [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## Is this possible? thanks!
> 
> View this message in context:  
> [http://www.nabble.com/newbie-question-about-rendering-partials-and-rhtml-tf3692733.html#a10324965](http://www.nabble.com/newbie-question-about-rendering-partials-and-rhtml-tf3692733.html#a10324965)  
> Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> >

–  
[http://www.web-buddha.co.uk](http://www.web-buddha.co.uk)

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 5, 2007, 1:35am UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/3 "2007-05-05T01:35:01Z")

</div>

Hi Dave,

I read up on layouts, (

> **[Radar - O’Reilly](https://www.oreilly.com/radar/?page=2)**
>
> Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

[Radar – O’Reilly](http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html?page=2) )

and it made me wonder why you cant specify a specific layout inside an  
action? i tried placing the: layout “standard-layout” inside one of my  
action def’s, but i ended up with an error.

it this not possible?

Dave G. wrote:

> and the magic will take place.
> 
> > wondering if there was some way i could reference this from the rhtml  
> > of
> 
> –  
> [http://www.web-buddha.co.uk](http://www.web-buddha.co.uk)
> 
> >

–  
View this message in context:  
[http://www.nabble.com/newbie-question-about-rendering-partials-and-rhtml-tf3692733.html#a10332020](http://www.nabble.com/newbie-question-about-rendering-partials-and-rhtml-tf3692733.html#a10332020)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 5, 2007, 9:51am UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/4 "2007-05-05T09:51:28Z")

</div>

The “layout ‘standard-layout’” call is a class method call that sets the  
layout for the whole controller.

To specify a specific layout for an action, pass it to render:

def fooaction

# do something

render :layout =\> ‘super-special-layout’  
end

b

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 5, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/5 "2007-05-05T20:05:14Z")

</div>

thanks for clearing that up…i have another question…this may be  
more of a design question…our existing website has 2 templates, and  
we determine which one to show based on screen size, which is  
determined through javascript…i.e.

now i am trying to determine how to do this…basically all of my  
actions behave the same, except they have a different layout…

but i am a bit confused…it doesnt seem like i can do this on the  
server side…i.e. in the controller…or in the .rhtml file…so  
should i redirect with a id specifying which template? (i.e. set the  
window.location to specify the id in the url, and then base the  
template on that?

im not sure if i have been very clear…so if this is confusing…let  
me know…and i’ll try and clear it up…

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 5, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/6 "2007-05-05T22:09:27Z")

</div>

I guess it depends how much of the difference between the two templates  
is  
presentational is handled by css. If so, the javascript can still do  
it’s  
thing. The rhtml layouts should only contain structural information (ie  
html/xhtml). Clarify a little more?

On 5/5/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> {
> 
> ```
> 
> actions behave the same, except they have a different layout…
> 
> > > and it made me wonder why you cant specify a specific layout inside an  
> > > in the
> > > 
> > > > On 5/4/07,gmoniey[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > > > 
> > > > > file?  
> > > > > to edit in case i make a change to my header or footer (i.e. if i  
> > > > > [http://www.nabble.com/newbie-question-about-rendering-partials-and-rh](http://www.nabble.com/newbie-question-about-rendering-partials-and-rh)…  
> > > > > Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
> > 
> > > > –  
> > > > [http://www.web-buddha.co.uk](http://www.web-buddha.co.uk)
> 
> >

–  
[http://www.web-buddha.co.uk](http://www.web-buddha.co.uk)

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 6, 2007, 1:49am UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/7 "2007-05-06T01:49:42Z")

</div>

gmoniey wrote:

> Hi,
> 
> im not sure if i am on the right path here, so i figured i would ask.
> 
> Basically, all of my pages have the same header and footer, and i was  
> wondering if there was some way i could reference this from the rhtml  
> file?

In the view you can do this

\<%= render “blog/header” %\>

blah lbah

\<%= render “blog/footer” %\>

PS: I would rather create one layout which include header and footer 🙂

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [May 6, 2007, 12:40am UTC](https://www.ruby-forum.com/t/newbie-question-about-rendering-partials-and-rhtml/103361/8 "2007-05-06T00:40:41Z")

</div>

the two layouts are actually very different…different images,  
different static text, different tables, div’s etc…

i have been thinkin about this more and more…and it seems like the  
best way to do it would be something like this:

and have the action handle which template will be shown from there on  
out (since this really only need to be figured out the first time the  
page loads), however…im worried about the case where the user wanted  
to go back to the homepage…i.e. [http://www.mysite.com](http://www.mysite.com), i would need  
a way to ensure that the javascript is run again…
