Results 1 to 6 of 6

Thread: using the same HTML code on each page

  1. #1
    Join Date
    Apr 2007
    Location
    Southwest France
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default using the same HTML code on each page

    Hi All
    Just a quick one I am using the same bit of code over and over so can it be placed externally and called as and when needed,
    also it's quite a heavy bit of code slowing the page down a bit, would this make it any slower in loading

    Great site.

    Steve C.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The code won't do too much to make anything slow, since it's a very small file. Likely, any image, even a small one, will be bigger, so the page itself won't cause much trouble.

    As for using the code on each page, that's easy using PHP.
    1. You must have PHP installed/enabled on your server.
    2. You must have the extension of the file end in .php
    3. For any php code it must be surrounded by <?php ..... ?>
    4. PHP is parsed by the server, so it will not be output, but rather the result, so with this, just the contents of the included file will be sent, not the php command.

    Wherever you want to put the html/text, use this:
    <?php include('myincludedfile.ext'); ?>

    Simple as that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2007
    Location
    Southwest France
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Trying to keep it all client side as its a large form and can be cached local,
    is there a way of calling a .htm file in the same manner as a script .js file, I'm messing about with it all but not getting anywhere,
    any pointers anyone.

    Merci

    Steve C

    ps. many thanks for the above but grappling with French & HTML is enough languages for me, PNP is a long way off.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Server-side is definitely the way to go. PHP is probably the best-supported, but if you don't want to learn a whole new language you might want to try something like SSI (Server-Side Includes) which is basically a "special set of tags" that can be used to perform some simple server-side operations (such as including files). Your server will need to support it, of course, as with PHP.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP isn't complex at all if you just use includes.

    Here's a complex breakdown of everything you need to know:
    PHP Code:
    <?php //open tag
    include('path/myfile.ext'); //include will get the contents of another file and output them.
    //path/myfile.ext is the location of the file.
    //if the file doesn't exist, it will give an error.
    /*Close tag >>*/ 
    ?>
    Client side for this would be more complex and wouldn't really save anything notable in terms of load for the client or server. It would be more taxing on the browser, as well.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Apr 2007
    Location
    Southwest France
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    1stly thanks for the help

    I've checked my hosting package and I have php4 en CGI (safe mode off) , php5 en CGI (safe mode off) , + phpMyAdmin, what ever thats for, so I gather I can do the following, I will give it a try and see if it works,
    I've tried using this but had some problems with running a script & with spacing issues. but it might help someone else.

    <object
    type="text/x-scriptlet"
    data="your-file-here.htm" height="585" width="600">
    </object>

    Regards

    Steve C.

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
  •