www.webdeveloper.com
Results 1 to 7 of 7

Thread: Organising Code better

  1. #1
    Join Date
    Feb 2006
    Posts
    31

    Organising Code better

    I want to organise my code better, and was wondering if i could create a script file with all the code in under calling commands and then in my html file i want to use whenever i want that code i can call it in from my sript file.

    so it would be something like the following...

    Script file:

    tester()

    <p>Test</>

    My html page file:

    <body>
    call tester()
    </body>

    ... and this would display 'Test'

    Is it possible to do this with html, i've looked everywhere and cant seem to find it, i thought it would have been possible, please help

    Thanks

    D

  2. #2
    Join Date
    Oct 2005
    Posts
    843
    html, dont think so. a server side yes. and i dont know about javascript but probally.
    Welsh

  3. #3
    Join Date
    Feb 2006
    Posts
    31
    how would i do it with php?

    or will i need to post this question in there??

  4. #4
    Join Date
    Oct 2005
    Posts
    843
    your page has to be like index.php. then inside it you can have something like
    PHP Code:
    <?php include("a-file.html"); ?>
    and say have the a-file.html contain your nav bar. and just place that on everypage where you navbar is suppose to go.
    Welsh

  5. #5
    Join Date
    Feb 2006
    Posts
    31
    yeah i knew how to do that in the first place - but i want one page with all my code in it - but you are able to select certain code within your page

    so ....

    tester()
    <p>hello</p>

    tester2()
    <p>put your name here</>



    then in my html file if i want both i can call both ...
    <body>
    call tester()
    call tester2()
    </body>

    or if i just wanted one i could say
    <body>
    call tester2()
    </BODY>

    is this possible even if i use php as a solution?

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,355
    data.php
    PHP Code:
    <?php
    function tester()
    {
      echo <<<END
    <h1>This Is a Test</h1>
    <p>It is only a test.</p>
    END;
    }
    function 
    tester2()
    {
      echo <<<END
    <p>This has been a test.</p>
    <p>The End</p>
    END;
    }
    ?>
    index.php:
    PHP Code:
    <?php
    require "data.php";
    ?>
    <html>
    <head><title>Sample Page</title></head>
    <body>
    <?php
    tester
    ();
    tester2();
    ?>
    </body>
    </html>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Jan 2006
    Posts
    27
    Quote Originally Posted by essjay_d12
    I want to organise my code better, and was wondering if i could create a script file with all the code in under calling commands and then in my html file i want to use whenever i want that code i can call it in from my sript file.
    I had the same thought with my webpage as well and thanks to the people here I was able to make it work. Here is the problem solution and in case you are interested, here my webpage with the implemented code (it's not done yet).

    HTH
    Markstar

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles