|
 |
|
 |
03-07-2006, 05:43 AM
|
#1 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
HTML 'include' abilities?
Hi all! New to the forum, but not new to programming.
OK - here's my challenge:
I have a website that I originally designed to be fast and safe. Not a lot of JAVASCRIPT, applets, etc. Also, I wanted it to be as vanilla as possible for the large number of browsers I expect will be viewing it (my latest statistics show that there are at least 10 different browser versions that accessed my site). So, I adopted a simple table layout, and built a framework that's used for each page - I just plop in the revelent text for each page and I'm good to go. So I thought.
After a few months of updates and refinements, I'm finding that maintenance is becoming a bear. If I want to update something in the 'fixed' portion of the page, I have to go back and change more and more pages to fix it. Now, I could easily convert my layout to a frame-based design, but I'm afraid that it will break with some browsers, and also mess up some of the webcrawlers (SEO is becoming important to me right now).
So, the question is, is there a way to 'include' HTML fragments into a larger HTML document so all I have to do is move the changed sections into place and when the page is referenced, the changes will be seen? If all else fails, I will convert to frames, but I'd rather not. Any suggestions?
If you want to see the site, it's cheffrankonline.com
Frank
|
|
|
03-07-2006, 07:15 AM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,471
|
hi frank, unfortunately the way to use 'includes' in html is to use frames. i think a lot of people would agree with me when i say that my opinion is that frames are horrible.
does your web server support php?
|
|
|
03-07-2006, 01:51 PM
|
#3 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
Your other alternative is to do sort of what dreamweaver does ... wrap fixed and dynamic portions of the site in '<!--' html comment tags, and then do search and replace on them before you upload the ste.
__________________
Stop intellectual property from infringing on me
|
|
|
03-07-2006, 04:13 PM
|
#4 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
Thanks for the replies !!!
I agree - frames are horrible. I designed a website about 8 years ago around frames. Since it was very graphics intensive, I wasn't worried about the overhead of frames. It loaded a lot slower than I would have liked.
I do have PHP - I run PHPBB as a forum there. I, unfortunately, don't know how to program PHP - although, I could probably learn if I had to. It's been a while since I had to learn a new language (believe it or not - it was JAVA in 1998 - and I've hardly used it at all!).
For now, I guess I'll have to resign myself to either long update sessions, or try not to have to update my 'fixed' areas.
I'm still open to other suggestions.
Thanks!
Frank
|
|
|
03-07-2006, 06:31 PM
|
#5 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,471
|
frank, if your server supports php, then spend a little of the time that you would be doing updating every page, and learn how to use php includes.
example here:
this is the top of every page
header.php
PHP Code:
<html> <head><title> my site</title></head> <body> Navigation: <a href=#>link 1</a> | <a href=#2> <br />
this is the bottom of every page
footer.php
now, let's make a page:
page1.php
PHP Code:
<? include("header.php"); ?>
<h1> this is my page 1</h1> fill the page with whatever you want.
<? include("footer.php"); ?>
lets make another page
page2.php
PHP Code:
<? include("header.php"); ?>
<h1> this is my page 2</h1> blah blah blah
<? include("footer.php"); ?>
now you can change the header and footer in a single file and it will update across your entire site.
if you dive further into php, then you will be able to store things like your recipes in a database. it would make it so all your articles and recipes could be displayed from a single script.
sorry i had to edit your post. we need to keep things work safe around here. i want to try that grilled lamb with mint spice recipe i saw on your site earlier  i had a funny story tonight, i went to linens and things to get a cast iron skillet. the emeril one was marked as 0.00. I took it up to the counter and asked, and the guy said it was $ .01. I thought he was kidding, but he wasn't. I told him I will take 2 then.  2 pans for 2 cents. made my day.
|
|
|
03-07-2006, 08:53 PM
|
#6 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
SDE - thanks for the heads up - and the edit . . . my apologies.
I worked as a professional photographer for a while, and while I did do some fashion and actually was editor of a magazine for a while, the real money was in 'glamour' - from Maxim to Playboy and beyond. And then, digital cameras were invented and the real photographers were not needed anymore. But, I digress . . .
Can I span a table between the "page 1" and "page 2"? For example, start the table with the first column in page 1, which is where my variable text would be, and end it on page 2, which is the fixed text? Also, would my page name now be "index.php" or something else?
Thanks in advance!
Frank
PS: Let me know how your lamb turns out - you can also use that sauce with what my kids called "lego lamb" (leg o' lamb). - F
|
|
|
03-07-2006, 09:31 PM
|
#7 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,471
|
yes, but let's clear things up. are you talking about displaying a recipe across 2 pages? my example was just to show that any page you want can include that header and footer.
your recipes would be prime for a php/mysql setup. learning php isn't entirely bad, it just takes a little energy. the benefit is that you would only have to design your recipe viewer page once, and then you could load up any recipe from a database using that exact same code. if you wanted to spread a single recipe across 2 pages, yes, that is possible too. you just need to organize your database accordingly.
when you decide if you want to just do php files for each recipe, or database the recipes, or even if you want to use php at all, let me know and i can point you in the right direction for the next step.
|
|
|
03-08-2006, 04:25 AM
|
#8 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 661
|
Here's another way
index.php
PHP Code:
<html> <body> <table> <tr> <!-- start side navigation <td> <a href="index.php?recipe=1">link 1</a><br/> <a href="index.php?recipe=2">link 2</a><br/> <a href="index.php?recipe=3">link 3</a><br/> </td> <td> <?php // Start the dynamic content/recipes
if (isset($_GET['recipe']) && preg_match('#[a-z0-9_]#i', $_GET['recipe'])) { // cool the visitor wants to see my recipe $recipe = 'recipes/'.$_GET['recipe'].'.html'; if (is_file($recipe)) { // the requested recipe exists include($recipe); } else { // the recipe does not exist include('no_recipe.html'); } } else { include('index.html'); } ?> </td> </tr> </table> </body> </html>
Now you write your recipes inside the 'recipes' folder just like any other html file, BUT without the <html><body> part.
|
|
|
03-08-2006, 05:20 AM
|
#9 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
Actually, the question was about a table spanning, in your example, header and footer.
<?
include("header.php");
<!-- This has the <table> tag and the <TD> and my first <TR> tags -->
?>
<h1> this is my page 1</h1>
fill the page with whatever you want.
<?
include("footer.php");
<!-- this is where I put my second <tr> </tr> pair and the </table> tag -->
?>
As I look at how PHP works, it's apparent that would be no problem doing that. What (I think) PHP is doing is building the HTML from other files without interpreting them - the browser will be doing that. <smacking head!!>
DJMaze - thanks for that example. I have to actually play with it a bit to get comfortable with the language, but it's really not that hard! I actually wrote a word processor back in 1979 that was very much like HTML with some PHP capabilities (conditional processing and 'include' processing - it let me build a meta-document made up of many different files - and, I did it in BASIC, to boot!!).
Thanks for the assistance all!!
Frank
|
|
|
03-08-2006, 05:55 AM
|
#10 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
WooHoo!!!!!!!
I converted one 'easy' page to PHP using the example by SDE -
http://www.cheffrankonline.com/doit.php
I also found you can nest includes. This means my navigation bar becomes independent from the header/footer - meaning one less update if I ever add another option there. This is coding the way I like it - I was always a lazy programmer and if I could find a way to do something once, and pull it in when I need it, I would. Most of my code libraries were larger than the programs I was writing (at that time, COBOL and a propriatary language called "TAL", unique to Tandem Systems).
Thanks once again! I'll be back from time to time with questions that have me completely stumped, but are obvious to everyone else
Frank
|
|
|
03-08-2006, 06:37 AM
|
#11 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,471
|
try to keep it as simple as possible. yes, you can nest includes, but do you really need to nest the nav?
the header.php file will always be a single file, and if you need to change the nav, you can change it there.
now there may be exceptions, but a good rule of thumb is 'you should only use includes for code that you will re-use (or html you will type again in another file)'
so, for the navigation, to me it would make sense to put it in a seperate include perhaps if you were going to put it on the top and the bottom of the page. ( in the header and footer )
DJMaze brings up a good point. You can store your recipies in text files in a sub-directory named 'recipes.' Using that bit of php code in the middle ( which probably looks intimidating if you've never used php before ) you can dynamically call the recipe from the URL.
example: The recipe exists in the recipe directory: /recipe/grilled_lamb_with_mint_sauce.html
Now you can call it in the url by typing: http://cheffrankonline.com/recipe.ph...ith_mint_sauce
The PHP code just looks for the html file and includes it in your page. These recipe pages would not include the header and footer. They are the files being included into the recipe.php page.
Glad you got it working. The more time you spend with PHP, the less time you will spend maintaining your websites.
|
|
|
03-08-2006, 06:29 PM
|
#12 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
SDE -
The nav bar is located at both the top and bottom of the page, so nesting it within both the header and footer makes sense.
DJMaze -
I started playing with your example. I split one of my HTML files which contains both chatty stuff and recipies into a PHP document which now pulls the recipies from the /recipes directory, and has the other stuff within. I think I now understand how include works. However, taking your example for dynamic page creation, I'm having problems. I'm going to move over to the PHP forum and we can discuss there. Thanks in advance.
Frank
|
|
|
03-08-2006, 06:40 PM
|
#13 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,471
|
woohoo! .. sounds like chef is converted! 
|
|
|
03-08-2006, 07:22 PM
|
#14 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
Not so much a matter of being converted, as finding the proper tool for the job. I used to have this argument all the time with users when I was a systems architect. A user will read something about something, and want to design a system around it. Usually, it wasn't an appropiate use for that particular something. I also had the opposite problem when I would specify a specific language or piece of equipment for an application because it was (better, faster, cheaper - pick any two), and would have to deal with people who wanted to do it the way they always did it.
If I was still working professionally in IT, I would have no problems with converting HTML pages to PHP. No reason not to do so now, especially since I am effectively dealing with the same problems - cost of maintenaince, flexability, and expansion.
I have to hit Amazon and get a couple of primers on PHP and probably within a couple of weeks, I'll be able to solve problems on here, too
Frank
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 09:32 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|