...

View Full Version : Can't do include from sub-folder.?



Buffmin
03-15-2012, 09:27 PM
I have a normal shtml file.
I use
<!--#include file="footer.shtml" --> on my index page to include my footer.

I have a page in in a sub-folder and would also like to include that footer,but when I do
<!--#include file="../footer.shtml" -->
It does not get included on the sub page. Not sure why?
Any help would be appreciated. Thanks. Buffmin

dan-dan
03-15-2012, 09:40 PM
Are you sure it's just 'one' folder in the way eg: root/folder/folder/file.shtml

Does it work using the absolute path?

Buffmin
03-15-2012, 09:48 PM
Yes, it is definitely one folder down. Not sure how to set the absolute path. You mean using the url?

I did try the <!--#include file="http://www.mysitename.com/footer.shtml" -->

No help.

I see thatb there is aome kind of trick to using includes from sub-folders (but I don't know it!)

dan-dan
03-15-2012, 09:53 PM
Does it work with http://www.yoursite.com/footer.shtml?

dan-dan
03-15-2012, 10:03 PM
Is the page in which your trying to include the file a HTML or SHTML?

Buffmin
03-15-2012, 10:09 PM
Both are shtml

I used the same <!--#include file="footer.shtml" --> that I used in the index.shtml file. When it didn't work, I added the ../ and still didn't work. And it is definitely only 1 folder level down.

dan-dan
03-15-2012, 10:34 PM
I've heard of problems between html and shtml and needing to add to htaccess. Otherwise I don't know.

Buffmin
03-15-2012, 10:35 PM
Sorry, all are shtml

I tried it again with a new page. I find that if you include a say.... footer.shtml page and in the same folder, you create a page that has nothing but an include to that page it works fine. (using <!--#include file="footer.shtml" --> )

BUT if you copy that same page to a sub folder, it will no longer include the footer code, even if you add the ../ before the footer.shtml

I just get an error .... [an error occurred while processing this directive]

I don't get it.?

Fou-Lu
03-15-2012, 11:13 PM
SSI is a server directive. Hmmm, I think I'll move this to the other server side languages forum.

Don't bother with tracking your filepaths. The directive is html root based, just use /footer.shtml if its served off of the root.

Buffmin
03-15-2012, 11:23 PM
I tried <!--#include file="/footer.shtml" -->
Still no good.

Fou-Lu
03-15-2012, 11:27 PM
Does that include line show up in the comments if you view the source of the page?


Wait, change that from file= to virtual=. Does that work?
On a side note, its been yeeeeeaaaaarrrrrssss since I've used an SSI directive. Is there a reason why you are using this instead of a processing language like PHP?

Buffmin
03-15-2012, 11:37 PM
No it doesn't.
You can see the page at http://cert.cnjwebsolutions.com/garb/junk.shtml

When I view source, below is what I get. (The only thing I put on the page is the footer include)
AND, below that is the original code from my page)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

[an error occurred while processing this directive]
</body>
</html>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<!--#include file="../footer.shtml" -->
</body>
</html>

Buffmin
03-15-2012, 11:47 PM
Got it.
I finally found this in another forum

rather than use <!--#include file="../footer.shtml" -->

Change it to this <!--#include virtual="/footer.shtml" -->

and here is the explanation exact from the forum.

-------------------------
What you have should work fine, basically. Because it does not work, something else is wrong.

any path that starts with a slash means, "Start at the DocumentRoot" -- as defined in the server configuration. So if /inc/example-page.shtml is referenced in an include, but resolves to <DocumentRoot>/sub-folder/inc/example-page.shtml instead of <DocumentRoot>/inc/example-page.shtml, then either your server configuration is faulty, or it is simply not configured the way that you think it is... That is why I asked about the "Control Panel add-ons" above.

[added] Here is the code I use to include a footer on all pages of one of my sites, regardless of what subdirectory the page's file might be located in:

-----------------------

Thank you all !!
Working fine now. Cheers.

Fou-Lu
03-16-2012, 12:06 AM
Right, so... exactly what I suggested :)

Buffmin
03-16-2012, 12:49 AM
Wow Fou-Lu.

My apologies. I guess my eyes skimmed over that, thinking it was just one of those tid-bit (phrases) that people seem to include in their threads.

Yes, that is exactly what you suggested.

The other thing that you asked was, why am I not using a processing language like php.

Hmmm, as I am fairly new in this business, I have always had the impression that you should create sites as html unless you are going to include php code, at which time, I would save them as .php.

That has always been a question of mine. If php pages will work fine even if they do not contain php code, then why not just always save pages as php?

I mean, I have a tendancy of creating half a website, and then the client wants a page that will require php. Then, rather than having 10 html pages and '1' php page, I go back and save the other pages as php.?

I would appreciate your thoughts. Thanks again, Buffmin

Fou-Lu
03-16-2012, 01:02 AM
The expense of the pre-processor on a static page IMO isn't worth needing to go back later to convert it. If there is any indication that the page will not remain 100% static, I'd use a processing language for it. Whether or not it changes is somewhat irrelevant with machines nowadays.
Nothing says you can't use partial static and partial dynamic. PHP (and even SSI for that matter), will gladly include a .html page and place it where requested. The included blocks could be static, but I'd still suggest dynamic .php or .aspx or whatever processing language you want to use just so if it does become dynamic you don't need to write an addtype to process .html as .php, and won't need to correct the extensions later.

Includes are a fundamental when it comes to PHP, and almost always in use in every script. Its pretty much the same as the SSI, but you can't get away with /includefile.php since PHP isn't jailed to the document root like ssi is.

So IMO, I personally think that its worth the pre-process expense to plan ahead.

Buffmin
03-16-2012, 06:36 PM
Makes sense. very good points. Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum