Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Including Files

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    2
    Member #
    13251
    Is there any way I can "include" a file into my code? I've written menu code, but I don't want to copy/paste it into every html file in my site. If I copy/paste, I would have to change every single file when the menu code was changed. Can someone help me please?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey.

    A common question leads to a common answer!

    Off the top of my head, 3 ways (all achieve the same, but have different pro's and con's).

    Method 1: The .js file

    You have a file of JavaScript code that is full of document.writes' and inside them is your menu code.
    Then, in your .htm page, whereever you want the menu to appear, you have something like:
    HTML Code:
    <script src="menu.js"></script>
    Where menu.js is the name of your js file

    Pros: Do not need any fancy features on your host (server side languages), you will be used to the code.
    Cons: Users can disable JavaScript, meaning there will be no navigation!

    Method 2: The iframe.

    The iframe (inline frame) is a popular choice, as it loads a document/file into an area of the page which you can set it's width and height. Another benefit is that you can change the document/file that is displayed without refreshing the rest of the page. Sample code:

    HTML Code:
    <iframe src="menu.htm"></iframe>
    Pros: good browser support, users cannot really turn off (some add-ons can help users block certain files, but do they have a reason to?)
    Cons: If user is using an old browser, nothing will appear, May take longer to load as however many extra files have to download.

    Method 3: The server side include

    A standard way of achieving what you ask. Normally, there is a header file and a navigational file in this setup. Sample code (in ASP, then PHP).

    Code:
    <% <!--#include file="menu.htm"--> %>
    PHP Code:
    <?php include("menu.htm"); ?>
    Pros: Very easy to achieve (even if not familar to a server side scripting language, it's no bother).
    Cons: You will need a host with the correct technology (ASP, PERL, PHP).

    I forgot to mention, all 3 have another pro of course, which is if you edit the menu file, then the changes will cascade through the site, making your life easy.

    Good luck.

  4. #3
    Junior Member
    Join Date
    May 2006
    Posts
    2
    Member #
    13251
    Thank you so much for your quick and throrough reply. I decided to use the php approach, and it's perfect for me! Thanks!

    God bless,
    Lukas

  5. #4
    Member
    Join Date
    Mar 2006
    Posts
    84
    Member #
    12765
    agreed, you really have several different ways of including files.

  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    lukas ...

    Using PHP gives you one extra super powerful thing ....

    You can embed PHP scripting right inside your page.

    That could be such things as date processing, reading from a text file,
    displaying random images, displaying things only if someone is logged in ...
    which utilizes the PHP "sessions" functions ... very neat stuff.

    Making your page "dynamic" ... that's the thing to do.


  7. #6
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Look into Server Side Includes.. SSI's... (make sure you have handlers set...)

    This way you can includes files even if you do not use a secripting language such as php... and you don't need to use potentially search engine unfriendly methods such as frames or iframes...



    -Hagen
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  8. #7
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    Hagen ... WTF?! May 22 ? OP already decided he was going the PHP route :laugh:
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us

  9. #8
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Very true I am hoping it will benifit other people reading this who don't have scripting capabilities!

    -H
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  10. #9
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    bsfog has already stated that and explained SSI and well as PHP in his post :errm:
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us

  11. #10
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Oh my god you're right! I humbly appologise, for all the confusion I have caused...
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:57 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com