# Newbie... Layouts and how to create universal header through

**URL:** <https://www.ruby-forum.com/t/newbie-layouts-and-how-to-create-universal-header-through/90807>\
**Category:** Rails\
**Created:** [April 1, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/newbie-layouts-and-how-to-create-universal-header-through/90807 "2007-04-01T23:09:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AbsolutZero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@AbsolutZero](https://www.ruby-forum.com/u/AbsolutZero)\
**Post date:** [April 1, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/newbie-layouts-and-how-to-create-universal-header-through/90807/1 "2007-04-01T23:09:31Z")

</div>

I have a simple question that I’m sure will be painful to answer for  
some of you experts, but I thank you for bearing with me…

I want a simple 5-page website. I have a custom header consisting of a  
simple banner and horizontal navbar underneath it. I’d like this to  
stay the same through every page. Now some of my pages are interactive  
with the user like shopping carts etc, but some are static, like a  
current news section. I made a controller for each page, so that each  
page would get a View associated with it. The way I have my pages  
written now, is that the code for the banner and navbar appear on the  
top of each individual page.rhtml in the /views/layouts section, and  
then each page has its individual content on its respective  
index.html.

The main problem I see, is that if that header changes, I have to go  
into each individual layout and change it, and I know thats definitely  
not the way to do it, but I can’t figure out how to render that code  
at the top of each layout…

Any help is greatly appreciated.

Thanks.

-Dan

---

<div class="post-metadata">

**Author:** ![AbsolutZero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@AbsolutZero](https://www.ruby-forum.com/u/AbsolutZero)\
**Post date:** [April 2, 2007, 12:58am UTC](https://www.ruby-forum.com/t/newbie-layouts-and-how-to-create-universal-header-through/90807/2 "2007-04-02T00:58:42Z")

</div>

Hey AbsoluteZero, you can do the following:

a) create a partial for your header (e.g.  
app/views/shared/\_header.rhtml )  
b) create a partial for your nav bar (e.g.  
app/views/shared/\_nav\_bar.rhtml )  
c) create a partial for your footer (e.g.  
app/views/shared/\_footer.rhtml )  
d) setup your layout app/views/layouts/application.rhtml

Untitled Document \<%= javascript\_include\_tag :defaults %\>

\<%= render :partial =\> ‘shared/header’ %\>  
\<%= render :partial =\> ‘shared/nav\_bar’ %\>

\<%= yield :layout %\>

\<%= render :partial =\> ‘shared/footer’ %\>

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![AbsolutZero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@AbsolutZero](https://www.ruby-forum.com/u/AbsolutZero)\
**Post date:** [April 3, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/newbie-layouts-and-how-to-create-universal-header-through/90807/3 "2007-04-03T22:55:17Z")

</div>

Thank you so much, thats exactly what I was looking for!

---

<div class="post-metadata">

**Author:** ![AbsolutZero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@AbsolutZero](https://www.ruby-forum.com/u/AbsolutZero)\
**Post date:** [April 3, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/newbie-layouts-and-how-to-create-universal-header-through/90807/4 "2007-04-03T23:10:19Z")

</div>

For a quick screencast tutorial on how layouts are selected see the  
“All About Layouts” at [http://www.railscasts.com/](http://www.railscasts.com/)
