# Include HTML

**URL:** <https://www.ruby-forum.com/t/include-html/74286>\
**Category:** Rails\
**Created:** [November 3, 2006, 1:56pm UTC](https://www.ruby-forum.com/t/include-html/74286 "2006-11-03T13:56:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [November 3, 2006, 1:56pm UTC](https://www.ruby-forum.com/t/include-html/74286/1 "2006-11-03T13:56:24Z")

</div>

Hi,

how do you include html into a web page.

e.g i have a menu that is present on every page so i want to include it.

also would this go in the public directory where the stylesheet  
directory resides

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [November 3, 2006, 2:03pm UTC](https://www.ruby-forum.com/t/include-html/74286/2 "2006-11-03T14:03:34Z")

</div>

matt wrote:

> Hi,
> 
> how do you include html into a web page.
> 
> e.g i have a menu that is present on every page so i want to include it.
> 
> also would this go in the public directory where the stylesheet  
> directory resides

I am new to rails but as I know you can put code in the  
application.rhtml - that will appear in every page

i have a menu in my app too and use  
\<%= render :partial =\> “shared/header” %\>  
to include it

andreas

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [November 3, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/include-html/74286/3 "2006-11-03T14:30:39Z")

</div>

thanks for your reply…could you give an example?

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/include-html/74286/4 "2006-11-07T10:58:07Z")

</div>

On Fri, 2006-11-03 at 13:56 +0100, matt wrote:

> Hi,
> 
> how do you include html into a web page.
> 
> e.g i have a menu that is present on every page so i want to include it.
> 
> also would this go in the public directory where the stylesheet  
> directory resides

* * *

sounds like something that should go on a layout…

app/views/layouts

[http://rails.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html](http://rails.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html)

Craig

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [November 3, 2006, 2:40pm UTC](https://www.ruby-forum.com/t/include-html/74286/5 "2006-11-03T14:40:32Z")

</div>

The app/layouts/application.rhtml file will “wrap” your entire website,  
if you like. You could create your basic layout in this file, including  
your menu that should be everywhere, and at the point in your layout  
that the dymamic content from your rails application would go, you would  
put:

\<%= yield %\>

(Used to be content\_for\_layout)

Whenever you hit a piece of your application, the view for the  
method/action will be inserted where the “yield” is and the entire page  
will be returned. The AWDWR book has an excellent overview of how this  
works in the tutorial.

Now, if you do not want to use the application layout, you can create a  
partial - that is, a view with the just code for your menu - and put it  
into one of the folders under app/views, with a name that begins with an  
underscore, like “\_nav\_menu.rhtml”. Then, anywhere you want to display  
that menu in a view, you would call it as a partial. Many people will  
create a common folder under app/views for this kind of stuff, like the  
previous poster who suggested putting it into  
“app/views/shared/\_nav\_menu.rhtml”. Then, you would call the partial  
with the following:

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

Note that in the render call for a partial, you do not use the  
underscore or the .rhtml prefix - rails knows.

c.

matt wrote:

> thanks for your reply…could you give an example?
