Including html files within html

Hi there,

I need to include a header file in some HTML pages. However, I have an issue with these .html pages not working when converted to .php files. I do not know why this is. The files are from a script purchased from Themeforest who no longer support the product.

What I would like to know is, can I include other HTML files within another HTML file?

I have found this:

But wondered if this is the correct way about it, or if there are better ways?

Any advice would be great, thanks!

Hi, I guess your site is hosted on a server using PHP.

Files with the .php extension contains php scripts that are meant to be processed on the server and usually combines html with php commands to output a html page and send as a respons to the browser.

Please read more about how to include files in PHP:

https://www.php.net/manual/en/function.include.php

as a general aside… reproducing the code for what amounts to getElementById is probably not efficient no.

If you’re running Apache, you can include SHTML files within other SHTML files.

Can you embed an HTML file within one With the

<embed type="text/html" src="header.html" width="500" height="200">

What exactly have you tried? And how do you define “not working”?

Hi,

I have tried the following:

<!--#include file="./inc/header.shtml" -->

Which is in the following directory structure:

/httpsdocs/tests/inc/header.shtml

I have included this file inside a file in here:
/httpsdocs/tests/folder-one/page.shtml

However, nothing is showing.

I have tried
<!--#include file="../inc/header.shtml" -->

But still no luck.

Do I have something wrong here, or my reference to the file in the parent directory incorrect?

Do you have SSI enabled?

Just to test that it is working, try putting both files in the same directory and use

<!--#include file="header.shtml" -->

Thanks, I have tried that and it doesn’t seem to appear, so I’m guessing I don’t have it enabled.

Do I need to contact my host to enable it?

Do you have access to the httpd.conf file? Hopefully this guide should help.

Thanks for the link. I don’t think I do have access to it. My host uses Plesk so will look into that or ask them. When I connect to FTP, I only have httpdocs as the root and not in the /etc/httpd/conf as described

You do have the calling file with a “.shtml” suffix, yes? By default it won’t work if the file is something.html

So you are trying SHTML includes. I assumed from the initial question you were trying PHP includes. Or did you try that too?
Assuming PHP is running on your server, it should be fairly straightforward to do.

Yep, both files are .shtml

The script I am running doesn’t seem to run when I change the extension to .php (they are .html files with angular, but it doesn’t seem to like PHP), otherwise I would use PHP includes which would work fine.

When I try to change the extension to .php, the pages load blank.

I’ve managed to get it to show - I added this to a htaccess file:

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

I now can’t seem to include it from a directory above where the file that is including it is in.

Am I doing something stupid?!

<!--#include file="../../inc/header.shtml" -->

The file is in:

/httpsdocs/tests/directory-one/file.shtml

and the file I would like to include is in:

/httpsdocs/tests/inc/header.shtml

This is the real problem. Focus on resolving this instead of looking for a hack that “works”.

1 Like

The script/item that I purchased from ThemeForest works fine, but just not when I convert to PHP.

I have just worked it out and it was that I had to use virtual= rather than file=

<!--#include virtual="../inc/header.shtml" -->

2 Likes

Glad you got it sorted. Just as a note, if it doesn’t contain any SSI, the file you’re including (in this case header.shtml) doesn’t need to have an SHTML extension; it can be just HTML.