#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    37
    Rep Power
    3

    Problems using #include to include html doc


    I am having trouble including code from an html document in another html document. I am currently using an Apache 2.2 testing server. Is it required for the included file to have an .shtml extension? Also, does the html code in the included file have to have html, head, and body tags or could it simply contain a <div>?
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Unless you configure the server to run .html files through the SSI processor, you need to use a .shtml extension.

    Included files are not separate documents, so they should not contain such tags if the parent document contains them. If you're not sure if you're doing it right, check the "View Source" in your browser and use the HTML validator (which you should use anyway).

    P.S. I would recommend that you use PHP includes instead of SSI, since PHP provides many more capabilities that you might like to use in the future.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    50
    .shtml is not required; but proper server configuration is, whether .shtml is used or not. It is likely that your server doesn't allow server side includes.

    See: http://httpd.apache.org/docs/2.0/howto/ssi.html

    You do not want to repeat the html declaration or head information. Your #include might be part of the head section though. Think of the resulting file as one contiguous html file.

    If your server won't allow html SSI, don't despair. If you don't mind a .php file name, you can get the same effect using a couple of lines of very basic PHP.
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    .shtml is not required; but proper server configuration is, whether .shtml is used or not.
    Hmm... True. Some servers might not have it enabled by default.

    If you don't mind a .php file name, you can get the same effect using a couple of lines of very basic PHP.
    PHP files don't have to have .php extensions. However, I recommend hiding the file-name extensions of the pages with mod_rewrite (so it doesn't matter what they are).
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    37
    Rep Power
    3
    Thanks, I appreciate the replies. I will give that site and try and check back.

    I am not using .php b/c the document is an .htm one, and I'm aware that I can change it to .php and use 'include()' but I prefer not to.

    Originally Posted by Kravvitz
    PHP files don't have to have .php extensions.
    Not true, they do have to have a .php extension unless you configure the htaccess file accordingly.
  10. #6
  11. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Not true, they do have to have a .php extension unless you configure the htaccess file accordingly.
    Yes, I know. I was implying that just like files that include SSI directives don't have to have a ".shtml" extension, files that contain PHP code don't have to have a ".php" extension.

    I am not using .php b/c the document is an .htm one, and I'm aware that I can change it to .php and use 'include()' but I prefer not to.
    A PHP file does not have to have any PHP code in it. You can use as little or as much PHP as you want.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo