SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    html include not working

    Hello,
    I was hoping someone could help me figure out why my html include was not working. In a previous thread, a while ago, I was told one can include html from another file using the following syntax: <!--#include virtual="pathToFile.html" -->

    Is that I am trying to use html includes in the following, and much simpler example, but the point is that they don't seem to be working.

    I have an index.html, which has the following syntax and a live copy is up here:
    Code:
    <!Doctype HTML>
    <html lang="en">
    	<head>
    		<title>Red bg on no script</title>
    		<!--#include virtual="include.html" -->
    	</head>
    	<body>
    		<h1>Heading</h1>
    		<p>Paragraph</p>
    	</body>
    </html>
    and the file it includes is up here and the contents of that file is:
    Code:
    <style type="text/css">
    	body{
    		background:#ff0000;
    	}
    </style>
    So when one views index.html, shouldn't the include be included and the body's background be set to red?

    Does anyone have any ideas on how to fix this?

  2. #2
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    What programming language are you using for the include?
    <!--#include virtual="include.html" --> ???
    Maleika E. A. | Rockatee | Twitter | Dribbble



  3. #3
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    What happens if you change the file extension to .shtml as in index.shtml

    Basically, you have to be sure that your server is set up to process SSI, then you have to tell it to look for includes by using the correct file extension.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    A nicer solution (IMHO) is to use PHP includes, but your pages need to have a .php extension (well, you can avoid that, but there's not much point generally). Anyhow, try what imaginekitty suggests anyway, so you at least know what the issue is.

  5. #5
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @kohoutek : just normal html.

    @imaginekitty :
    Quote Originally Posted by imaginekitty View Post
    What happens if you change the file extension to .shtml as in index.shtml
    I don't know, i will try it tomorrow.
    Quote Originally Posted by imaginekitty View Post
    Basically, you have to be sure that your server is set up to process SSI, then you have to tell it to look for includes by using the correct file extension.
    But isn't it already looking for the correct file-extension ?
    The suggestion you made applies to the file calling the include (index.html in my example) not the file to be included (include.html), right?
    @ralph.m : What does IMHO mean?
    wait, a file using php includes can not have a .php extension?

  6. #6
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by team1504 View Post
    But isn't it already looking for the correct file-extension ?
    Wait, what? ?? If you have a php file but you call it index.html it just serves it without processing it because the server doesn't know to process it as a php file. Same thing with SSI. It doesn't know to use includes because you didn't use the proper file extension. It's just serving it as is.
    Quote Originally Posted by team1504 View Post
    The suggestion you made applies to the file calling the include (index.html in my example) not the file to be included (include.html), right?
    Yes.
    Quote Originally Posted by team1504 View Post
    @ralph.m
    wait, a file using php includes can not have a .php extension?
    Wait, what? ??

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by team1504 View Post
    What does IMHO mean?
    IMHO, it means In My Humble Opinion. Get with the web lingo, man! (It's all kinda new to me, I admit. Too old for this kid talk. )

    wait, a file using php includes can not have a .php extension?
    You can tell your server to process PHP in .html files by adding this to your .htaccess file:

    Code:
    AddType application/x-httpd-php .html

  8. #8
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    You can tell your server to process PHP in .html files by adding this to your .htaccess file:

    Code:
    AddType application/x-httpd-php .html
    I was going to see if SSI works and then pop a php_info (); on him.

    Ultimately, above either, my suggestion would be ASP.NET MasterPages but it may not be necessary.

  9. #9
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,447
    Mentioned
    274 Post(s)
    Tagged
    5 Thread(s)
    Off Topic:

    Quote Originally Posted by ralph.m View Post
    IMHO, it means In My Humble Opinion. Get with the web lingo, man! (It's all kinda new to me, I admit. Too old for this kid talk.)
    Me too - but you can look trendy with the help of http://www.acronymdb.com/

  10. #10
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginekitty View Post
    Quote Originally Posted by team1504
    But isn't its already looking for the correct file-extension
    Wait, what? ??
    I have no idea What I meant. I think it was a confusing way to ask the second question I asked you (confirmation on which file will have the .shtml extension).
    Quote Originally Posted by ralph.m View Post
    IMHO, it means In My Humble Opinion. Get with the web lingo, man! (It's all kinda new to me, I admit. Too old for this kid talk. )
    Haha. I know that feeling. I found abbreviations and emoticons for things/words ive never heard of. Idk, btw,and ttyl are enough for me.
    Quote Originally Posted by ralph.m View Post
    You can tell your server to process PHP in .html files by adding this to your .htaccess file:

    Code:
    AddType application/x-httpd-php .html
    wait, wouldn't that prevent the server from processing PHP in .php files? Or should the line be:
    Code:
    AddType application/x-httpd-php .html, .php
    ?

  11. #11
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TechnoBear View Post
    Off Topic:

    Me too - but you can look trendy with the help of http://www.acronymdb.com/
    Haha nice. Thank you for the link @TechnoBear — ill have to take a look at that!

    Btw, how do you do the off topic highlight? I have seen it a few times on the forums, but never asked how to do it.

  12. #12
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by team1504 View Post
    I have no idea What I meant. I think it was a confusing way to ask the second question I asked you (confirmation on which file will have the .shtml extension). ...
    Ah. The calling file should have the special file extension. The include file can be anything, even .txt or .inc or .blah, as long as it matches the file in the include statement.

  13. #13
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,447
    Mentioned
    274 Post(s)
    Tagged
    5 Thread(s)
    Quote Originally Posted by team1504 View Post
    Btw, how do you do the off topic highlight? I have seen it a few times on the forums, but never asked how to do it.
    You wrap it in [ot] opening and closing tags which, AFAIK (= as far as I know ) you need to type yourself - there isn't a button.

  14. #14
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by team1504 View Post
    ... I don't know, i will try it tomorrow. ...
    Tomorrow was yesterday. Ahoy, ahoy?

  15. #15
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginekitty View Post
    Tomorrow was yesterday. Ahoy, ahoy?
    Apologies, I had a busy weekend and I guess I went a little too off topic. Speaking on which, thank you @TechnoBear for teaching me how to highlight off-topic (parts of) posts.

    Back on topic, i tried changing index.html to index.shtml and opened it again in chrome and the background was not red. So that means that the include did not work properly, right?

    Here are new links to the files as I changed the extension of index.html to index.shtml (so the old links won't work):
    1.) index.shtml
    2.) include.html

    Sorry for keeping you, @imaginekitty waiting much longer than it should have been .

  16. #16
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ain't no thing.

    OK, see it does work on my server: http://imaginekitty.com/team1504.shtml (I made no changes except for the file names)

    Is dropbox.com your only host? You'll have to use a proper host to get such functionality.

    I doubt they offer PHP but try making a page called test.php and make the contents of the file exactly this:
    Code PHP:
    <?php php_info() ?>
    Upload it and go to that page using your browser to see if it works.

  17. #17
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    it doesn't work. Dropbox doesn't support PHP. But if it works now on your sever then I trust that it will work on my actual server.

    Once i make the changes and upload the site, if i have questions, do you mind if i PM you?

    Also if and when @ralph.m is online can he or anyone else answer my question on the line to add to the .htacess file to get php parsed in .html files?
    Here it is again:
    Quote Originally Posted by Team1504
    Quote Originally Posted by ralph.m
    You can tell your server to process PHP in .html files by adding this to your .htaccess file:
    Code:
    AddType application/x-httpd-php .html
    wait, wouldn't that prevent the server from processing PHP in .php files? Or should the line be:
    Code:
    AddType application/x-httpd-php .html .php
    ?

  18. #18
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I don't think you really want .html files parsed as PHP. Just because you can doesn't mean you should.

  19. #19
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well i just wanted to know how to do the .htacess change properly for learning sake.

    But why wouldn't i? I know that you be a dangerous questions to ask, but it seems like an okay solution.

    i think a bad thing about it is that i have to change the .htacess file.
    Meaning, my HTML document will be parsed as html, as html in a php document outside of the <?php ?> tags is, and the includes will be parsed as PHP— i don't see any issues with that.

  20. #20
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by team1504 View Post
    Also if and when @ralph.m is online can he or anyone else answer my question on the line to add to the .htacess file to get php parsed in .html files?
    I probably shouldn't make comments on stuff I don't understand well enough. That line used to work for me when I had PHP on a .html page (for testing only, as I don't do it in real life) but on my new server it doesn't work, so so much for that. I gather different servers require different .htaccess code, but none of the ones I've seen work on my new server (I've just tested them). So now I can't test whether not having the .php in the htaccess rule stops PHP working on .php pages or not. Sorry!

  21. #21
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    no problem. I will try it out as well as the .shtml solution out! and report back!

  22. #22
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kohoutek View Post
    What programming language are you using for the include?
    <!--#include virtual="include.html" --> ???
    Quote Originally Posted by team1504 View Post
    @kohoutek : just normal html.
    No, that's not "just normal HTML" -- it's called SHTML, hence the 'need' for a SHTML extension or a htaccess/config file change to make it work...

    I'd be a little surprised that Kohoutek hadn't heard of it, if not for it being an Apache specific feature that nobody seems to actually use anymore; especially since a lot of hosting providers no longer enable the Apache module to support it, and most any server side language is significantly more capable. Was all the rage a decade ago.

    The APPROPRIATE changes to your htaccess to enable SHTML being:
    Code:
    AddType text/html .shtml
    AddHandler server-parsed .html
    AddHandler server-parsed .shtml
    Options Indexes FollowSymLinks Includes
    Which will turn it on in both .html and .shtml files.

    http://httpd.apache.org/docs/2.2/howto/ssi.html

    The relevant documentation for it.

  23. #23
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Oh, NOT that you should be using it to include CSS in STYLE tags, since that defeats the point of an external stylesheet and adds it together SERVER side instead of client side, and skips right over the use of MEDIA targets.

    That's LINK's job.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •