Include common HTML code within another HTML doc

Discussion in 'HTML & Website Design' started by Garrett, Aug 30, 2006.

  1. #1
    Hi there,
    I've a (x)HTML question that I can't find the answer for (it's probably obvious) but I find it difficult to phrase for the ol' search engines.

    Basically, I have a site using CSS and HTML, which uses a menu strip along the top of the window. Because of the design the HTML for the buttons and topbars (logo, etc) is repeated in each HTML page of the site. If I make any changes I need to replicate them in each file. Is there any tag to import a section of code from a common HTML file?

    cheers
    G
     
    Garrett, Aug 30, 2006 IP
  2. rooneydavid

    rooneydavid Guest

    Messages:
    67
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Since HTML is static you can not include a common page. What you should do is convert your site to SHTML which would allow for includes. Then you would put your header in a file called header.inc and place this code in your html
    <!--#include file="header.inc" -->
    HTML:
    where you what the header! If you are on a Unix or Linux server you can use the .htaccess file do rewrite rule on .html files to process through SSI (Server Side Includes). And that is the only way you can do it other then a dynamic language.
     
    rooneydavid, Aug 30, 2006 IP
  3. Garrett

    Garrett Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for that, most interesting. Time for some research into SSI.
     
    Garrett, Aug 30, 2006 IP
  4. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Another option is with PHP includes. Adjusting the server to process to html files as php or renaming them to .php's and adding <?php include 'blahfile.php'; ?> would do it.

    If you plan on really getting into webpages, I recommend learning about php anyway, and includes are an easy way to start.
     
    Gordaen, Aug 30, 2006 IP
  5. Garrett

    Garrett Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I've actually got the server set up to process html as php, as I've put a few counter scripts in. It looks like a php include is another good option. Thanks!
     
    Garrett, Aug 31, 2006 IP