navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

'Include file' code, to include htm file in an htm file

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> 'Include file' code, to include htm file in an htm file
Page: [1]
 
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
'Include file' code, to include htm file in an htm file - 11/15/2007 17:50:42   
Is it possible to write 'include' code to easily 'include' an .htm file in another .htm file?

I have some text that I want to include in every .htm page on my site, but this text ('what's on this month') will change each month, so I'd like to write some code to incorporate this other .htm file easily.

I have read on this site: w3schools how to include an .asp file inside another .asp file. I have never worked with .asp files before, and anyway I was thinking it might be better if I didn't change all my site pages to .asp files (from .htm files) because I might lose my positioning in the Search Engines.

Also, if using ASP is my only option, and I'm using PHP for a form on the site, is it better not to mix ASP and PHP on the one site?

P.S. I don't want to use FrontPage to create this code.

Thanks for any thoughts!

spinningjennie
womble

 

Posts: 5702
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/15/2007 18:37:13   
You can't mix ASP and PHP - it's either/or. If you're using PHP you can just use:

<?php include("yourfile.html"); ?>


You'll need to change the page filetype to .php though.

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to spinningjennie)
Tailslide

 

Posts: 6292
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/16/2007 2:44:52   
Or you can use SSIs

<!--#include virtual="/includes/header.txt"-->


with the content to be included contained in a .txt file.

But you'd need to change your file type to shtml.

If you're on a Linux box then you can keep your html suffix if that is important to you (and if you're not using FrontPage for anything as this will mess up FP extensions):

AddType application/x-httpd-php .htm .html .shtml .php


That bit in your .htaccess file will ensure that you can keep the .html instead of having to change it to .shtml or .php

Just another quick point in case you've not used SSIs or PHP includes - you only have the stuff you actually want included in them - nothing else at all. I say that because I think that with FP includes you have a load of other stuff such as all the head markup etc (could be wrong though).

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to womble)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/16/2007 6:14:38   
Many thanks Womble and Tailslide for the code tips, both of which I'll explore.

Q1. Womble, just to clarify, do you mean that I can't have some pages in my site as .php files and other pages as .asp files in my site?

Tail, you've just alerted me to SSIs, which are new to me, and about which I've just found some very brief, though not fully comprehensive info at this link: http://www.w3.org/Jigsaw/Doc/User/SSI.html#include. The code used there is:

<!--#include file="included.html" -->

Q2. Tail, can you or anyone else explain the meaning of the addition of the word 'virtual' to the code?

Q3. Also if I change my file type to .shtml, even if I can add the code you suggest to the .htaccess file, would I have to change my DocType declaration within the .shtml file?

I'm using this now:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Thanks also for the reminder that with files that will be included in another file, that I need to remove everything outside the <body> tags.

Thanks and regards, spinningjennie



< Message edited by spinningjennie -- 11/16/2007 6:26:44 >

(in reply to Tailslide)
Tailslide

 

Posts: 6292
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/16/2007 7:21:19   
Hi SJ!

The addition of the word Virtual is to enable you to include the file if it's in a different directory - without it, the included file would have to be in the same directory. It might be, might not, so easiest to just have virtual just in case!

The DOCTYPE is fine whichever way you go.

And yep include files only contain the stuff you actually want included - nothing else at all.

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/16/2007 8:31:44   
Thanks again Tail.
Q1. So for the .txt file do I only include content, no table tags, that I would like to include?

Q2. If I change my file names to .shtml (and use the code in the .htaccess file to convert them to .html) when I create links to internal pages do I link to an .shtml file, or perhaps to an absolute http://www file on the hosting server?

Q3. In IE6 it seems that in order for my navigation menu links to colour correctly I need to link to .html files and not .htm files (no problem in IE7, FireFox, Opera or Safari). Can I specify in the .htaccess code you suggest that the .shtml file converts to only an .html file?

(See this page: http://www.crcl.org.au/ccfin.htm and you might see that the Bowls Ladies submenu links (with .htm ending) and the Tennis submenu links (also with .htm ending) may colour differently each time you load it in the IE6 browser. (Other Sport menu links are to .html files and consistently colour correctly.

Thanks for any thoughts! After midnight now, so to rest!
spinningjennie


< Message edited by spinningjennie -- 11/16/2007 8:38:22 >

(in reply to Tailslide)
Tailslide

 

Posts: 6292
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/16/2007 9:00:09   
Hi again

A1 - what I do is build the whole normal HTML page - then copy/paste the bit that I want in the include into the .txt file (or .php file if I'm using PHP includes) - then delete it from the original page replacing it with the include call. So if you want a table with stuff in it in the include - put the whole table, tags and all in the include. If you only want a particular row then put everything from <tr> to </tr> in it.

There'd be nothing to stop you just adding the content and no tags but the tags would have to exist in the original page around the include call.

A2 - No if you can get the .htaccess thing to work then you can leave the files as .html. You only need to change the filetype if you can't get the .htaccess thing working. There'd be zero difference within the site with links etc - everything as it was before.

A3 - it's not changing the filetype to .html - it's treating .html files as though they were .php files (or .shtml etc etc).

As far as the IE6 thing goes - can't reproduce the problem here. My guess is that maybe it's to do with the a:visited rule in the stylesheet (or lack of - couldn't see one, maybe I missed it!). You really need a:link, a:visited, a:focus, a:hover and a:active rules for links to get the right combo working.

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/22/2007 8:30:52   
I just can’t get the ‘include’ txt files to be included into the .htm web pages (see this page despite making additions to the .htaccess file so that the .htm web pages are being treated as though they were php files or.shtml etc.

.htaccess file: 1st step taken:
In the .htaccess file I added:

AddType application/x-httpd-php .htm .html .shtml .php

It didn’t work after I also added the 'include' code into the web page (as per 2nd step taken, below.)

Then instead, I tried adding the same code without the ‘application/’ and with fewer ending bits:

AddType x-httpd-php .php .htm .htm

after reading this link

(strangely the .htm is repeated here but that’s how I keep reading it recorded on various internet sites)
(I checked the .htaccess file after I changed the code and it had updated as I intended.)

After using the adjusted AddType code I did at one stage manage to successfully get the footer.txt to include into this page but I can’t manage to repeat it, and the sidebarleftinner.txt has never included.

Note1: What concerns me about this revised .htaccess code is that I think from what Tailslide said that I want the .htm file to be treated as an .shtml file, rather than a .php file, but there’s no reference to .shtml in the code so maybe that’s why the code doesn’t work. However, adding it made no difference.

Note 2: My hosting server is a Linux/Apache server, so I don’t know whether that is the same as just a Linux server, which Tail said was required for this code to work.


Web page file: 2nd step taken:
In the .htm page http://www.crcl.org.au/ccfin1.htm I added this code near the bottom:

<!--#include virtual="/include/sidebarleftinner.txt"--> and further down this code:
<!--#include virtual="/include/footer.txt"--> and higher up this code:
<!--#include virtual="/include/test.txt"-->

but it didn’t work.

Any tips much appreciated.

regards,
spinningjennie

(in reply to Tailslide)
Tailslide

 

Posts: 6292
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/22/2007 8:57:38   
try adding .shtml as a document type in the .htaccess file see if that helps.

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to spinningjennie)
Donkey

 

Posts: 3917
Joined: 11/13/2001
From: Blackfield United Kingdom
Status: online

 
RE: 'Include file' code, to include htm file in an htm ... - 11/22/2007 8:57:54   
You need to add a space before the final two dashes on SSI's
e.g.
<!--#include virtual="/include/sidebarleftinner.txt" -->



This Link will give you more of an explanation of SSI

Is your path correct? Your SSI code implies that all your includes are saved in a folder called "include" which is inside the root directory. If this is not the case try creating one and move the files ending ".txt" into it.

< Message edited by Donkey -- 11/22/2007 9:20:06 >


_____________________________

:)

I have a higher and grander standard of principle than George Washington. He could not lie; I can, but I won't.
Samuel Clemens

(in reply to spinningjennie)
William Lee

 

Posts: 1179
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/22/2007 12:39:07   
quote:

ORIGINAL: spinningjennie



AddType application/x-httpd-php .htm .html .shtml .php



I can still see the include directive code in the source. This means SSI is still not enabled on your server.

Try add this to the .htaccess file after the a/m code

AddHandler server-parsed .htm

Or see http://www.outfront.net/tutorials_02/adv_tech/htaccess_magic2.htm

_____________________________

William Lee

pǝssǝɟoɹd-ɟ1ǝs ʎɥʇɹoʍʇsnɹʇ ʇsoɯ ɹnoʎ
nɹnb ǝsɐqɐʇɐp & dsɐ ,ʍɹp ,ǝbɐdʇuoɹɟ





(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/23/2007 8:35:23   
Thankyou to all! Now working! Tailslide, Donkey, William Lee! I thought I’d rewrite the whole process that worked, for my own working manual, and in case it helps others. Sorry it’s so long!

This is what worked.

Step 1. Added this code to the .htaccess file so that my .htm page would be handled by the server like an .shtml page and allow the SSI Includes to work. (I didn’t want to change my file ending to .shtml, and thereby lose search engine positioning.)

AddType x-httpd-php .htm .html .shtml .php
AddType text/html .html
AddHandler server-parsed .html
AddHandler server-parsed .htm

Note A:
I did however find that all 4 lines of code above could be simply replaced by this code suggested by William Lee below, and the Includes worked! (I have however decided to keep the above 4 lines in the .htaccess file, just in case more is somehow better!)

AddHandler server-parsed .htm

Q. Does this last line of code do exactly the same as the 4 lines of code above?

Note B:
Note that the 1st line of code (of the 4 above) has removed the application/ from the code I tried originally which was:

AddType application/x-httpd-php .htm .html .shtml .php

Advice on that matter is located at: http://forums.digitalpoint.com/showthread.php?t=7584

Note C:
Tailslide, I’ve now been able to keep the .shtml in the 1st line added to the .htaccess code above. I guess the server must now be treating the .htm page as an .shtml page, thereby allowing the SSI to work.

Note D:
William Lee: thankyou for this fantastic link for .htaccess tips!
Outfront link on .htaccess tips

Note E:
I did read in the previous link:
‘.. files which must be parsed by the server before being displayed will load more slowly than standard pages. If you change things as above, the server will parse all .html and .htm pages, even those that do not contain any includes. This can significantly, and unnecessarily, slow down the loading of pages without includes.’

I do, however, have includes in all but one page of the website, so hopefully speed will be OK.

Step 2. ‘Include’ code in page itself
In the page itself I added this ‘include’ code:
<!--#include virtual="/include/test.txt" -->
<!--#include virtual="/include/sidebarleftinner.txt" -->
<!--#include virtual="/include/footer.txt" -->

Note F:
Note that following Donkey’s advice I did try the --> both with and without the space before the 2 dashes, and both worked. Donkey, I have now noticed it written in various places with the space so I’ve left it in just in case it’s better.

Note G:
When creating the file that will be included into the web page, I saved it as .txt file (eg footer.txt). The .txt file has no tags for DocType, body, header etc. It only requires the tags for the inclusion itself (eg start with <p> tag or <table> tag) The best approach is as Tailslide advised earlier. First write the code for the inclusion within the final web page itself, then cut and paste that code into a new .txt file which will create the ‘inclusion’.

Note H:
When having difficulties with getting the .htm file to include the .txt file, in order to isolate the cause to either the web page and/or the included file, versus the .htaccess file, I saved my .htm web page as an .shtml page and found that the ‘includes’ did work. I then knew that the problem lay in the .htaccess file, which was supposed to be allowing the server to read the .htm web page as an .shtml page.


Hope I haven't put you to sleep with all this writeup.

Thanks so much.
spinningjennie


< Message edited by spinningjennie -- 11/23/2007 23:39:47 >

(in reply to William Lee)
Donkey

 

Posts: 3917
Joined: 11/13/2001
From: Blackfield United Kingdom
Status: online

 
RE: 'Include file' code, to include htm file in an htm ... - 11/23/2007 8:52:08   
Re the space before the dashes. It is to distinguish the include from normal non-printing comments in your code which should not have the space. Some servers don't seem to mind but I only know about this because one of my hosts changed servers a few months ago and suddenly some of my includes stopped working.

_____________________________

:)

I have a higher and grander standard of principle than George Washington. He could not lie; I can, but I won't.
Samuel Clemens

(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/23/2007 23:43:08   
Thanks again Donkey for that extra explanation!

regards,
spinningjennie


(in reply to Donkey)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/23/2007 23:53:41   
Today, I had a go at using the php include that Womble suggested first off, for the purposes of learning more. The reason I didn't start with this approach was that the option of being able to keep my .htm file endings suited me best for SEO (and I'm not sure if I could still do that with the php approach).

It didn't work for me but perhaps I made an error of some kind.

This is what I did:

1. Saved my web page file as this .php web page file and included this code into it to create the left side bar with calendar listing.

<?php include("/sidebarleftinner.html"); ?>

2. I couldn't open the webpage at all because I got the message, 'Do you want to open or save this file?' When I opened it, it opened in Dreamweaver.

Though I have now successfully used the SSI approach, I would be curious to understand why this didn't work, if anyone has any insights.

Cheers
spinningjennie

(in reply to spinningjennie)
William Lee

 

Posts: 1179
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/23/2007 23:56:46   
Many years ago when I started on ASP I received this similar msg. Reason is because my server is not configured for ASP.

Might be the same reason in your case for PHP:)

_____________________________

William Lee

pǝssǝɟoɹd-ɟ1ǝs ʎɥʇɹoʍʇsnɹʇ ʇsoɯ ɹnoʎ
nɹnb ǝsɐqɐʇɐp & dsɐ ,ʍɹp ,ǝbɐdʇuoɹɟ





(in reply to spinningjennie)
Tailslide

 

Posts: 6292
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/24/2007 3:23:44   

quote:


This is what I did:

1. Saved my web page file as this .php web page file and included this code into it to create the left side bar with calendar listing.

<?php include("/sidebarleftinner.html"); ?>

2. I couldn't open the webpage at all because I got the message, 'Do you want to open or save this file?' When I opened it, it opened in Dreamweaver.




What I do is to save the chunk of stuff to be included as a .php file rather than a .html file. The main page itself is a .html page.

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/24/2007 23:15:47   
Thanks Tail, this change worked! I made my included file a .php file and my webpage either an .html or an .htm page. Both worked.

Thanks William. Yes, PHP is enabled because I have a .php enquiry form that works, and was told by my web hosting provider that PHP was enabled.

spinningjennie



< Message edited by spinningjennie -- 11/24/2007 23:43:33 >

(in reply to Tailslide)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/24/2007 23:36:51   
I have just discovered I have to make a change to the 4 lines of coding in the .htaccess file which I used to get this SSI code to be recognised:

<!--#include virtual="/include/footer.txt" -->

It seems that the 4 lines of .htaccess code I listed on 11/23/07 at 8.35 stops another web page, my .php secure enquiry form, from showing in the browser.

quote:

AddType x-httpd-php .htm .html .shtml .php
AddType text/html .html
AddHandler server-parsed .html
AddHandler server-parsed .htm


When I replaced the 4 lines by the single line of code suggested by William Lee:

AddHandler server-parsed .htm

then both my web page with the include, and my .php secure enquiry form worked.

Perhaps someone can fathom the reason for this. And I'm also wondering if William Lee actually intended for me to use only this single line of code, because he mentioned I should add it after the a/m code (and I'm not sure what a/m means).

Regards, spinningjennie






(in reply to spinningjennie)
William Lee

 

Posts: 1179
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/25/2007 21:01:12   

quote:

ORIGINAL: spinningjennie


And I'm also wondering if William Lee actually intended for me to use only this single line of code, because he mentioned I should add it after the a/m code (and I'm not sure what a/m means).

Regards, spinningjennie



a/m means above-mentioned, which when I wrote it, I was referring to this line

AddType application/x-httpd-php .htm .html .shtml .php

Acutally I intended you to add that AddHandler line immediately after this line, so any wonderful results arising from just using the Addhandler line only is purely coincidentally, certainly I did not think it would have work just using that line only.

_____________________________

William Lee

pǝssǝɟoɹd-ɟ1ǝs ʎɥʇɹoʍʇsnɹʇ ʇsoɯ ɹnoʎ
nɹnb ǝsɐqɐʇɐp & dsɐ ,ʍɹp ,ǝbɐdʇuoɹɟ





(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/26/2007 0:26:01   
Thanks William for the clarification on a/m!

spinningjennie

(in reply to William Lee)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/26/2007 7:50:27   
Apologies for making a meal of this discussion, but in case it helps anyone, I thought I should probably add my latest (and final!) discovery to it, which may be the best way to go:

As a result of reading this:
Link re. enabling SSI via htaccess

Just in case it's better I've now replaced this single line in my .htaccess file:

AddHandler server-parsed .htm

with:

AddType text/html .shtml
AddHandler server-parsed .htm
AddHandler server-parsed .html
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes

and both my .php enquiry form and my web page with includes still work.

Thanks again to all and cheers
spinningjennie

(in reply to spinningjennie)
treetopsranch

 

Posts: 1155
From: Cottage Grove, OR, USA
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/26/2007 21:51:15   
I wish someone would test the above.htaccess changes in a FP extension enabled web. I know Tailslide said that it will mess up the extensions, but I have made many changes to .htaccess files very carefully not to disturb the extension data in that file and I was successful.

_____________________________

Don from TreeTops Ranch, Oregon

"I've got a taste for quality and luxury"


(in reply to spinningjennie)
spinningjennie

 

Posts: 309
Joined: 2/20/2002
From:
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/27/2007 7:50:14   
Treetops,
I'm in the final stages of recoding the site in xhtml 1.0 strict, so that it no longer depends on FP extensions. But at present the site is using FrontPage extensions to make its include pages work, and also to password protect a folder.

In the process of this discussion thread I've added the code of previous post to the .htaccess file without disturbing the .htaccess code that was already sitting there, and supposedly used by FP extensions. I found that the site that depends on FrontPage extensions was not affected by my additional .htaccess code.

However, I guess the risk is there that you could easily accidentally disturb the code already sitting in the .htaccess file. I've seen it written that it's a good idea to back up your .htaccess file before you make changes to it.

Regards,
spinningjennie


(in reply to treetopsranch)
treetopsranch

 

Posts: 1155
From: Cottage Grove, OR, USA
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/27/2007 10:31:24   
Thanks spinningjennie, that is good advice.

_____________________________

Don from TreeTops Ranch, Oregon

"I've got a taste for quality and luxury"


(in reply to spinningjennie)
Tailslide

 

Posts: 6292
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
RE: 'Include file' code, to include htm file in an htm ... - 11/27/2007 11:04:38   
Don - I have no personal experience of the .htaccess file corrupting stuff as I don't have FP but it's "received wisdom" from hanging round here too much!!

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to treetopsranch)
Page:   [1]

All Forums >> Web Development >> General Web Development >> 'Include file' code, to include htm file in an htm file
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts