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

Thread: Referencing an external file

  1. #1
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Referencing an external file

    I am working on a website that has many pages. Each page has the same header with drop down menus on the top. I want each page to get the source code for the headers from an external file. Part of the problem is that I want some of the code to import into <HEAD> and some of the code must drop into <BODY>. The content is contiguous, so it can post as one item across the head and the top of the body, but I am not sure how to make it happen. Any help? Thanks.
    Last edited by daddioja; 07-27-2006 at 08:11 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    what you are asking is possible, but I would need you to give me the code or a url to get the code otherwise I will not know where to break it up

  3. #3
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sample

    Sure pissa, the page is at www.ctap4.org. The drop down menus are the problem. I have many people updating pages, but it becomes difficult to update the menus. I want the information on the menues and the header graphics separate. Actually, the menu information itself is in the <head>, so i could have only that code reference an external file. Thanks for any help you can provide. Jason

  4. #4
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    if you are using php you can use : include ('external_filename.inc');
    you can include any amount of files you wish, so you can have for example:

    <head>
    include ('header_part.inc');
    </head>

    <body>
    include ('body_part.inc');

    ....
    Or you can just use one for entire top portion , just being sure to have the <body> tag in there where you want the breaks.

    You can google "php includes" for more help, but I sure hope you are using php because this is an extremely easy and effecient solution.

  5. #5
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, but we aren't using php. I was hoping for another solution, but if there are none, I guess we will need to change. Any other ideas?

  6. #6
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    what are you using then? Just general html?

    I would say that if you aren't using any (other) server side script, then your best bet IS php. The reason being that you can run your entire page in plain html and have the only instances of php be your includes.

    Forgive me if I simplify my solution, as I am not calling you a novice or anything just want to be clear if , indeed, you don't know anything about php.

    So basically if you're paying for your hosting, chances are its supports php. Thats basically all you need. A php supported server. Then you would map out your pages EXACTLY as you would in html. Then, locate the place where you want your external pages to load and place this code :

    PHP Code:
    <?php
     
    include ('name_of_external_file.inc');
    ?>
    (note your filename could be anything, header.html, header.php etc. it is just common to use ".inc" which represents "include")

    The <?php ?> tags open and close your php code. Everything that is not contained between php tags gets interpreted as html. So basically you can have a full html site, with only two snippets of php to load your pages.

    Then all you need to do is rename any pages containing your php includes to
    page_name.php

    And that's it. Again, please excuse me if you know all this, as I am in no way an advanced coder. The thing is I lay out all my pages in this exact way because yes, having external headers and footers saves A TON of useless hours hand coding potentially hundreds of pages!

    Let me know if this helps.

  7. #7
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    HTML Code:
    <script src="header.js">
    </script>
    <script src="footer.js">
    </script>
    superjadex12's idea is good too if daddioja is using any server side scripts

    if ur website plain old HTML this ur best bet

    i think
    Please don't mind me. I am just posting a lot of nonsense.

  8. #8
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    We are running cgi scripts and have naming requirements for the pages. If I understand correctly, php pages need to end in the .php extension, but I am not an expert so I easily could be dead wrong.

    In either case, I was hoping to run a javascript as mentioned by jr yeo. However, I am having trouble. Is it because part of the content is a java script? Here is the script I am trying to contain in the external file. Thanks for the help so far. Anything else will surely earn you good karma points.

    <script language="JavaScript">
    <!--
    function fwLoadMenus() {
    if (window.fw_menu_0) return;
    window.fw_menu_0 = new Menu("root",140,23,"Arial, Helvetica, sans-serif",12,"#ffffff","#000000","#7490c2","#99afd1");
    fw_menu_0.addMenuItem("Mission Statement","location='about_us/mission.htm'");
    fw_menu_0.addMenuItem("Description","location='about_us/description.htm'");
    fw_menu_0.addMenuItem("Plan","location='about_us/plan.htm'");
    fw_menu_0.addMenuItem("Brochure","location='about_us/brochure.pdf'");
    fw_menu_0.addMenuItem("State Map","location='about_us/statemap.htm'");
    fw_menu_0.addMenuItem("Regional Map","location='about_us/regionalmap.htm'");
    fw_menu_0.addMenuItem("Staff","location='about_us/staff.htm'");
    fw_menu_0.addMenuItem("Council","location='about_us/council.htm'");
    fw_menu_0.hideOnMouseOut=true;
    fw_menu_0.writeMenus();
    } // fwLoadMenus()
    //-->
    </script>

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

    Default

    if ur website plain old HTML this ur best bet
    Actually, using Javascript for includes is pretty daft.

    If you really can't use a server-side language to do it, I suggest you add it to all the pages individually. The *n?x utility sed might help you to do so and to update it later.

    If you put that directly into a .js file, it won't work. You have HTML tags (<script></script>) and HTML comments (<!-- -->) in there. Remove them.

    What sort of CGI scripts are you running? It is likely that you could use those to perform the insert.
    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!

  10. #10
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yeah, if you have to stick with cgi (maybe perl? ) then that's your best bet, I would guess to google perl includes, cgi includes, etc as I am not familiar with that.

    I would really emphasize NOT using javascript, because your entire website would then depend on a code that can be (easily) be disabled or just plain not supported. Accessability basically goes down the drain... whereas serverside is always executed, regardless of browser...

    p.s. yeah for php all files containing php have to end in .php

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
  •