# Including .html and .php files

**URL:** <https://www.ruby-forum.com/t/including-html-and-php-files/79683>\
**Category:** Rails\
**Created:** [December 18, 2006, 6:01am UTC](https://www.ruby-forum.com/t/including-html-and-php-files/79683 "2006-12-18T06:01:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![patwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@patwa](https://www.ruby-forum.com/u/patwa)\
**Post date:** [December 18, 2006, 6:01am UTC](https://www.ruby-forum.com/t/including-html-and-php-files/79683/1 "2006-12-18T06:01:00Z")

</div>

Hello. It’s been a long night of trying to get thisapplication  
developed so forgive me if this post is a bit messed up.

Is there a way to ‘include’ html files in an rhtml file? I have a  
standard.rhtml file in my layouts folder, and want to include another  
rhtml file that contains the code for a navbar created with Macromedia  
Fireworks. The file also has all the javascript, etc that goes along  
with it, as well as references to the individual images and rollover  
states that go with it. With a PHP page I’d just put \<?php  
include(‘navbar.htm’); ?\> but am not sure how to do it in ruby.

also, I know by default that a when going to an url that corresponds to  
a model/controller, the ruby engine will parse the code. But is there a  
way to include PHP code in there as well? E.g, if I want to use ruby to  
get information from a database, but then want to use PHP and plain html  
to create a form and send its contents using e-mail?

You can probably tell frm this that I’m new to ruby, and certainly at  
the present time most of my site will be using PHP/HTML. for the moment  
though, if anyone can advise me as to how I can get my navbar included  
into the rhtml file, I’d be grateful.

Cheers.

Hussein.

---

<div class="post-metadata">

**Author:** ![patwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@patwa](https://www.ruby-forum.com/u/patwa)\
**Post date:** [December 18, 2006, 6:39am UTC](https://www.ruby-forum.com/t/including-html-and-php-files/79683/2 "2006-12-18T06:39:40Z")

</div>

You want to use partials. Just make a new rhtml file and when you name  
it, make sure that you place an underscore before the first letter in  
the name. Then you can render it anywhere you want using render\_partial  
=\> “your\_partial\_name\_with\_no\_extension”

But why are you trying to include a navbar into the rhtml file? Aren’t  
you using your layouts folder? The layouts in your project should take  
care of everything for you.

---

<div class="post-metadata">

**Author:** ![patwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@patwa](https://www.ruby-forum.com/u/patwa)\
**Post date:** [December 18, 2006, 6:56am UTC](https://www.ruby-forum.com/t/including-html-and-php-files/79683/3 "2006-12-18T06:56:54Z")

</div>

Sean C. wrote:

> You want to use partials. Just make a new rhtml file and when you name  
> it, make sure that you place an underscore before the first letter in  
> the name. Then you can render it anywhere you want using render\_partial  
> =\> “your\_partial\_name\_with\_no\_extension”

more like:

#Stick your nav bar in app/views/some\_controller/\_foo.rhtml

\<%= render :partial =\> ‘foo’ %\>

Or from another controller:

\<%= render :partial =\> ‘some\_controller/foo’ %\>

> But why are you trying to include a navbar into the rhtml file? Aren’t  
> you using your layouts folder? The layouts in your project should take  
> care of everything for you.

Because it is on multiple pages, but not all? There are many reasons  
for keeping it encapsulated.

---

<div class="post-metadata">

**Author:** ![patwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@patwa](https://www.ruby-forum.com/u/patwa)\
**Post date:** [December 18, 2006, 6:57am UTC](https://www.ruby-forum.com/t/including-html-and-php-files/79683/4 "2006-12-18T06:57:30Z")

</div>

Hi. thanks for your reply.

To answer your question, being new to ruby I’m still a little unsure of  
how far I can go. I created the navbar with fireworks, so I have a  
directory of images with the .htm file containing the code. I’m just  
not sure how to include that code in the views rendered by Rails.

Also, when you said you can render partials, did you mean render the  
partials from within a different file:

E.g, I have a standard PHP file, included navbar, images, text, and so  
on, and then I have render\_partial =\> \_showbookings ?

Or did you mean the other way around? If so, how would I code it so that  
the contents of that html file are included within the given view (for  
example let’s say [http://localhost:3000/bookings/show](http://localhost:3000/bookings/show) linked to the  
show.rhtml file) would show my included navbar?

Hussein.
