Forum Moderators: mack

Message Too Old, No Replies

Best way to replace the same chunk of code across multiple pages?

how to make a chunk of code easy to replace?

         

Shenan

11:44 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



Hi everyone, first post here.

Is there a simple and efficient way to make a chunk of code that is repeated in all the pages of my site be easily replaceable/modifiable, so I don't have to manually edit each page with the same thing? Is there some kind of "include" type statement in html that I didn't find in the references that would allow me to keep this piece of code in a single file and have all the others reference it? Would this even be recommended?

A little background on this question: the reason I'm asking this is that I'm making up a new website and have a consistent menu on the left and top. The best way I could come up with to do this without using frames was duplicating the menu in all the pages, however, I am still working on the menu as I go along, so each change has to be made in all the pages. Am I just going about this in the completely wrong way? Is there a better strategy to do non-frames menus that are in all pages? I'm coding this site pretty much by hand (using coffeecup html).

Thanks in advance! :)

Shenan

txbakers

12:39 am on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi and welcome to WEbmaster World!

You can do includes with various types of server side languages such as PhP, ASP, and JSP.

You can also do them with .shtml files, but I think that has to be on a Windows server, though I may be wrong.

You can search here for SSI or Server Side Includes, which will give you tons of information on it.

And, yes, includes are THE way to go.

mack

12:41 am on Jan 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Hi Shenan,
Welcome to Webmasterworld.

It is very possible to do what you are wishing by using includes.

A lot of sites acheive this using php pages. In these situations what you will find is they have a page called index.php This page will include header.php main.php and footer.php

The header and footer files are used on all pages, but there is only one instance of each file, so any changes you make will be displayed on all pages that call the files as includes.

What you can do is have a file with your text body on it. then include it into each of your pages.. that way if you need to change the text you only need to update one file.

Mack.

Amanda

12:50 am on Jan 27, 2005 (gmt 0)

10+ Year Member



Yes, the php includes is what I use for my site, which is quite large and has a ton of pages. That way, when I add a new section to my site, I just have to add the link in the navigation in the header.php file, and not every single file, which would take forever.

tbear

12:55 am on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can also use php includes in existing .html pages by using htaccess to parse them for php.

Shenan

1:01 am on Jan 27, 2005 (gmt 0)

10+ Year Member



Wow, thank you everyone! I will get to work on this then. I haven't delved into PHP yet (still playing with HTML/CSS), but I imagine this should be fairly basic to do.

Thanks again for the help!

Shenan

txbakers

3:37 am on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



don't discount ASP or JSP in your search.

PhP is a great language, but so are ASP and JSP.

Shenan

6:48 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Txbakers, I didn't discount ASP and JSP out of hand. I'm sure they are great, and I see them used often on commercial sites so they must be powerful. But my needs are very simple at this time, and PHP just seems to be more commonly supported in the small website world right now in terms of hosting, information, user community, available scripts, etc. If I decided that I wanted to get a job in web development I would definitely try to learn ASP and JSP. This is just my newbie impression of PHP/ASP/JSP, so I could be wrong!

I did find some tutorials on how to do these header and footer includes. Couldn't be simpler.

Thanks again everyone! :)

wonderbread

6:58 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



One other option. If it is just something little, and you have a copy of Dreamweaver, they have a Find and Replace function. You can find it under the Edit menu...I use it all the time. I am pretty sure other HTML editors have some sort of similiar functionality.

- Nick