Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RoboCop001

macrumors 68000
Original poster
Oct 4, 2005
1,561
451
Toronto, Canada
Hey Everyone.

I'm trying to figure out SSIs.

Here's the one I include in every HTML file (shtml file, of course)...

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

Unfortunately, I have to have every single HTML page in the same folder as the topSection.html file in order for my includes to work.

So as you can imagine, very unorganized.

When I try to organize the HTML files into folders, the include no longer works.

Obviously it's because the <!--#include file="topSection.html"--> command is pointing to a file that's supposed to be in the same directory.

So naturally, I tried doing an absolute location like http://mywebaddress/folderBlah/topSection.html

But that doesn't work. I tried using that absolute path, and changing my include command to a virtual type like this <!--#include virtual="absoluteaddress/topSection.html"--> But that didn't work either.

Then I tried virtual with a relative path, nothing.

Unless the file is in the same folder, it says "an error occurred while processing this directive" where the Include would have gone, and displays the rest of the page fine.

I even tried the PHP include. Nothing appears at all, not even an error.

How do I tell it to look "one level up"? Is it <!--#include file="../topSection.html"--> like that? Does it have to be virtual for that to work? I tried ../topSection.html with both file and virtual but it still gives the error.

Is there some setting in the server that I have to change?? It's an Apache server.

Any tips are useful =)

Thanks!
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
virtual The virtual variable is used to specify a file path/name relative to the base directory of the HTTP server. The format is: 'virtual="'<filename>'"' where <filename>a file path/name relative to the base directory of the HTTP server.

file The file variable is used to specify a file path/name relative to the directory of the current document. The format is: 'file="'<filename>'"' where <filename>a file path/name relative to the directory of the current document.

The above is from a document I have. Not sure which is better for your situation, but you should be able to use either. In the code you gave try adding a space between the last " and the --> at the end of the declaration.

Code:
<!--#include file="topSection.html" -->

I know it seems like a small thing, but I remember having the same issue.
 

SrWebDeveloper

macrumors 68000
Dec 7, 2007
1,871
3
Alexandria, VA, USA
Also worth mentioning is some servers only parse .shtml files for SSI so if true simply rename your html file to use the .shtml extension.

In Apache two settings control SSI behavior, first make sure the Options directive has "Includes" enabled then use "AddType text/x-server-parsed-html .shtml" (a common configuration) or any extension you want, making a note that using .html has a minor performance hit as any file - even those without SSI - will still be examined. If you wish to control specific directories use the above commands in a local .htaccess. Otherwise they live in your Apache config file (i.e httpd.conf) of course.

So if you've got the syntax right as angelwatt said then check/set above and you'll be good to go. If you adjust the httpd.conf restart Apache after doing so. FYI.

-jim
 

RoboCop001

macrumors 68000
Original poster
Oct 4, 2005
1,561
451
Toronto, Canada
Hmm... it could be one of the server settings then.

Because the syntax is fine.

Here's my setup...

/site root{
-topSection.html
-/folder1{
----pageAboutThings.shtml
}
-anotherPage.shtml
-blah2.html
}

Now, in the page called anotherPage.shtml, I have this...
<!--#include file="topSection.html" -->
That works fine, since it's in the same directory.

Ok... So inside pageAboutThings.shtml, which is inside the folder "folder1" I have this...

<!--#include file="../topSection.html" -->

That results in "an error occurred while processing this directive" to appear where I placed the include. The rest of the page's content from pageAboutThings.shtml shows up fine.

I also tried...
<!--#include virtual="topSection.html" -->
<!--#include file="/topSection.html" -->
<!--#include virtual="http://fullwebaddress/topSection.html" -->
<!--#include file="..//topSection.html" --> (two slashes)

All of those result in the error stated above.

Any ideas?? Am I not writing it correctly? Last time I checked, typing ../ means to go up one level?
 

SrWebDeveloper

macrumors 68000
Dec 7, 2007
1,871
3
Alexandria, VA, USA
Please try:

Code:
<!--#include virtual="../topSection.html" -->

Only the virtual argument can be a full URL or relative path. The above can be run from any .shtml file within folder1.

Details here: http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html

You noted, "Nothing appears at all, not even an error" - and SSI always generates an error when the syntax is wrong, file not found, etc. so be sure to test topSection.html by loading it via browser address bar (http://yourdomain.ext/topSection.html) to ensure that the page displays properly by itself. If okay, maybe you've got a duplicate HTML header situation which is a common mistake when using SSI as a templating system. Dupe headers cause things to disappear and render oddly when two files both have <html> or <body> for example.

That's all I can think of at this point, honestly.

-jim
 

RoboCop001

macrumors 68000
Original poster
Oct 4, 2005
1,561
451
Toronto, Canada
Please try:

Code:
<!--#include virtual="../topSection.html" -->

Only the virtual argument can be a full URL or relative path. The above can be run from any .shtml file within folder1.

Details here: http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html

You noted, "Nothing appears at all, not even an error" - and SSI always generates an error when the syntax is wrong, file not found, etc. so be sure to test topSection.html by loading it via browser address bar (http://yourdomain.ext/topSection.html) to ensure that the page displays properly by itself. If okay, maybe you've got a duplicate HTML header situation which is a common mistake when using SSI as a templating system. Dupe headers cause things to disappear and render oddly when two files both have <html> or <body> for example.

That's all I can think of at this point, honestly.

-jim

That worked! Thanks so much! :D

I could have sworn I tried that before... maybe I had a typo.

Anyway, thanks for the help and the links!

Much appreciated :)
 

RoboCop001

macrumors 68000
Original poster
Oct 4, 2005
1,561
451
Toronto, Canada
Actually I just have one last question...

I have two servers. One for testing and one for the active webpage.

So because I'm using includes, my topSection.html file needs to have absolute paths. Otherwise it won't find the images and content inside the folder that the HTML file it's being loaded into resides in.

But since I have 2 servers, I'd need to have 2 absolute paths and make sure the correct path is in the file depending on which server it's on.

But is there a way to just tell it to point to the root directory of the website?

And is there a way to type something like this for a file path....

rootDirectory/folder1/blah.png

That way I don't need to worry about switching the paths in the file when I move it to the other server.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.