Reusing code?

Discussion in 'HTML' started by Brett Baisley, Feb 17, 2004.

  1. I have a web page that has html code that I would like to add to every page
    dynamically, instead of copying and pasting it to every page. That way, when
    it needs to be changed, it will be a lot less work.

    What is the best way to do this?

    Thanks

    Brett
    Brett Baisley, Feb 17, 2004
    #1
    1. Advertising

  2. Brett Baisley

    SpaceGirl Guest

    "Brett Baisley" <> wrote in message
    news:LmxYb.98780$...
    > I have a web page that has html code that I would like to add to every

    page
    > dynamically, instead of copying and pasting it to every page. That way,

    when
    > it needs to be changed, it will be a lot less work.
    >
    > What is the best way to do this?
    >
    > Thanks
    >
    > Brett



    Server Side Inlcude (SSI). Depends if your host supports it, and what
    language it supports.

    In ASP you'd do this...

    <!--#include file="myfile.inc" -->

    .....where "myfile.inc" can be any file within your website.
    SpaceGirl, Feb 17, 2004
    #2
    1. Advertising

  3. Brett Baisley

    SpaceGirl Guest

    "SpaceGirl" <> wrote in message
    news:c0u7u5$1bsn82$-berlin.de...
    >
    > "Brett Baisley" <> wrote in message
    > news:LmxYb.98780$...
    > > I have a web page that has html code that I would like to add to every

    > page
    > > dynamically, instead of copying and pasting it to every page. That way,

    > when
    > > it needs to be changed, it will be a lot less work.
    > >
    > > What is the best way to do this?
    > >
    > > Thanks
    > >
    > > Brett

    >
    >
    > Server Side Inlcude (SSI). Depends if your host supports it, and what
    > language it supports.
    >
    > In ASP you'd do this...
    >
    > <!--#include file="myfile.inc" -->
    >
    > ....where "myfile.inc" can be any file within your website.



    Actually you can include scripts this way too. You could for example have a
    page written in ASP include another ASP script at the top; for example for
    browser checking or whatever. Any server side scripts will get executed,
    even if they are "included".
    SpaceGirl, Feb 17, 2004
    #3
  4. Any way to get this to work with just pure HTML? I found that I can include
    a html file into another one, but then I'd have to change it to .shtml,
    which doesn't work well here for some reason.


    "SpaceGirl" <> wrote in message
    news:c0u82c$1bmaff$-berlin.de...
    >
    > "SpaceGirl" <> wrote in message
    > news:c0u7u5$1bsn82$-berlin.de...
    > >
    > > "Brett Baisley" <> wrote in message
    > > news:LmxYb.98780$...
    > > > I have a web page that has html code that I would like to add to every

    > > page
    > > > dynamically, instead of copying and pasting it to every page. That

    way,
    > > when
    > > > it needs to be changed, it will be a lot less work.
    > > >
    > > > What is the best way to do this?
    > > >
    > > > Thanks
    > > >
    > > > Brett

    > >
    > >
    > > Server Side Inlcude (SSI). Depends if your host supports it, and what
    > > language it supports.
    > >
    > > In ASP you'd do this...
    > >
    > > <!--#include file="myfile.inc" -->
    > >
    > > ....where "myfile.inc" can be any file within your website.

    >
    >
    > Actually you can include scripts this way too. You could for example have

    a
    > page written in ASP include another ASP script at the top; for example for
    > browser checking or whatever. Any server side scripts will get executed,
    > even if they are "included".
    >
    >
    Brett Baisley, Feb 17, 2004
    #4
  5. Brett Baisley

    SpaceGirl Guest

    "Brett Baisley" <> wrote in message
    news:ewxYb.98791$...
    > Any way to get this to work with just pure HTML? I found that I can

    include
    > a html file into another one, but then I'd have to change it to .shtml,
    > which doesn't work well here for some reason.


    To be honest I dont know! When it comes to server side scripting, I only
    know ASP. I'm pretty sure HTML is limited for this sort of thing; it's
    totally reliant on server technology to pre-assemble your content before
    it's sent out to the browser.


    >
    >
    > "SpaceGirl" <> wrote in message
    > news:c0u82c$1bmaff$-berlin.de...
    > >
    > > "SpaceGirl" <> wrote in message
    > > news:c0u7u5$1bsn82$-berlin.de...
    > > >
    > > > "Brett Baisley" <> wrote in message
    > > > news:LmxYb.98780$...
    > > > > I have a web page that has html code that I would like to add to

    every
    > > > page
    > > > > dynamically, instead of copying and pasting it to every page. That

    > way,
    > > > when
    > > > > it needs to be changed, it will be a lot less work.
    > > > >
    > > > > What is the best way to do this?
    > > > >
    > > > > Thanks
    > > > >
    > > > > Brett
    > > >
    > > >
    > > > Server Side Inlcude (SSI). Depends if your host supports it, and what
    > > > language it supports.
    > > >
    > > > In ASP you'd do this...
    > > >
    > > > <!--#include file="myfile.inc" -->
    > > >
    > > > ....where "myfile.inc" can be any file within your website.

    > >
    > >
    > > Actually you can include scripts this way too. You could for example

    have
    > a
    > > page written in ASP include another ASP script at the top; for example

    for
    > > browser checking or whatever. Any server side scripts will get executed,
    > > even if they are "included".
    > >
    > >

    >
    >
    SpaceGirl, Feb 17, 2004
    #5
  6. Ok, thanks anyway. Maybe I'll just code everything in asp or something.

    "SpaceGirl" <> wrote in message
    news:c0u8f5$1bs5g8$-berlin.de...
    >
    > "Brett Baisley" <> wrote in message
    > news:ewxYb.98791$...
    > > Any way to get this to work with just pure HTML? I found that I can

    > include
    > > a html file into another one, but then I'd have to change it to .shtml,
    > > which doesn't work well here for some reason.

    >
    > To be honest I dont know! When it comes to server side scripting, I only
    > know ASP. I'm pretty sure HTML is limited for this sort of thing; it's
    > totally reliant on server technology to pre-assemble your content before
    > it's sent out to the browser.
    >
    >
    > >
    > >
    > > "SpaceGirl" <> wrote in message
    > > news:c0u82c$1bmaff$-berlin.de...
    > > >
    > > > "SpaceGirl" <> wrote in message
    > > > news:c0u7u5$1bsn82$-berlin.de...
    > > > >
    > > > > "Brett Baisley" <> wrote in message
    > > > > news:LmxYb.98780$...
    > > > > > I have a web page that has html code that I would like to add to

    > every
    > > > > page
    > > > > > dynamically, instead of copying and pasting it to every page. That

    > > way,
    > > > > when
    > > > > > it needs to be changed, it will be a lot less work.
    > > > > >
    > > > > > What is the best way to do this?
    > > > > >
    > > > > > Thanks
    > > > > >
    > > > > > Brett
    > > > >
    > > > >
    > > > > Server Side Inlcude (SSI). Depends if your host supports it, and

    what
    > > > > language it supports.
    > > > >
    > > > > In ASP you'd do this...
    > > > >
    > > > > <!--#include file="myfile.inc" -->
    > > > >
    > > > > ....where "myfile.inc" can be any file within your website.
    > > >
    > > >
    > > > Actually you can include scripts this way too. You could for example

    > have
    > > a
    > > > page written in ASP include another ASP script at the top; for example

    > for
    > > > browser checking or whatever. Any server side scripts will get

    executed,
    > > > even if they are "included".
    > > >
    > > >

    > >
    > >

    >
    >
    Brett Baisley, Feb 17, 2004
    #6
  7. Brett Baisley

    Steve Pugh Guest

    "Brett Baisley" <> wrote:
    >> "SpaceGirl" <> wrote:
    >> > "Brett Baisley" <> wrote:
    >> > >
    >> > > I have a web page that has html code that I would like to add to every
    >> > > page dynamically, instead of copying and pasting it to every page. That
    >> > > way, when it needs to be changed, it will be a lot less work.
    >> > >
    >> > > What is the best way to do this?
    >> > >
    >> >
    >> >
    >> > Server Side Inlcude (SSI). Depends if your host supports it, and what
    >> > language it supports.

    >
    >Any way to get this to work with just pure HTML?


    No, HTML is not a programming language.

    If your server doesn't support any sort of include at all (so no SSi,
    PHP, ASP, etc., etc.) then you can either move to a better host, or
    look into solutions that work in you authoring environment, e.g. a
    preprocessor. See http://html-faq.com/utilities/?htmlpreprocessor and
    more generally
    http://www.allmyfaqs.com/faq.pl?Include_one_file_in_another

    Steve

    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <> <http://steve.pugh.net/>
    Steve Pugh, Feb 17, 2004
    #7
  8. Brett Baisley

    m Guest

    Brett Baisley wrote:

    > Any way to get this to work with just pure HTML? I found that I can
    > include a html file into another one, but then I'd have to change it to
    > .shtml, which doesn't work well here for some reason.


    Preprocessing is also an option. Any program that concatinates files
    will do, or you can use a more elaborate program.

    Under 'nix you can simply write a script with a number of calls
    similar to this, using cat and redirecting the pieces to a
    final html file with a karet:

    cat header.txt head.txt menu.txt body500.txt footer.txt > 500.html

    Similar things can be done under 'doze.

    It only takes moments to re-make a complete set of .html files, and
    then you upload them while you have a cup of coffee and pat yourself
    on the back.

    If you know a little perl, you can write a preprocessor using the
    File::Find module that will search and replace whole directory trees
    in just a few lines of code.
    --
    cheers m mbstevens.com
    m, Feb 17, 2004
    #8
  9. Hywel Jenkins, Feb 18, 2004
    #9
  10. Brett Baisley

    Paul Furman Guest

    m wrote:
    >
    > Preprocessing is also an option. Any program that concatinates files
    > will do, or you can use a more elaborate program.
    >
    > Under 'nix you can simply write a script with a number of calls
    > similar to this, using cat and redirecting the pieces to a
    > final html file with a karet:
    >
    > cat header.txt head.txt menu.txt body500.txt footer.txt > 500.html
    >
    > Similar things can be done under 'doze.



    Yep, in windows, you can make a text file named myfile.bat that contains
    simple dos commands, put it in the folder you want to process & click
    it. I forget what joins files but a > sends output to a new file like:

    dir *.html > htmlist.txt

    put that in a bat file & click it. Whatever the join commmand is, let's
    pretend it's [join]...so in a folder full of pages, with a subfolder of
    common header & footers:

    [join] common\header.htm *.htm common\footer.htm > results\*.htm

    or something like that <g>

    it's easy to just make it a dopey list with cut & paste too:

    [join] common\header.htm page1.htm common\footer.htm > results\page1.htm
    [join] common\header.htm page2.htm common\footer.htm > results\page2.htm
    [join] common\header.htm page3.htm common\footer.htm > results\page3.htm
    [join] common\header.htm page4.htm common\footer.htm > results\page4.htm
    [join] common\header.htm page5.htm common\footer.htm > results\page5.htm
    Paul Furman, Feb 18, 2004
    #10
  11. Brett Baisley

    Paul Furman Guest

    Steve Pugh wrote:
    >
    > ...If your server doesn't support any sort of include at all (so no SSi,
    > PHP, ASP, etc., etc.) then you can either move to a better host...



    I'd recommend PHP over (what I understand to be Microsoft based ASP type
    solutions). It's relatively easy & can do a heck of a lot more than just
    server side includes. You don't need to learn it all and it's free
    software so it doesn't cost much as an extra service. You can find bits
    of code for free for doing things like an email contact page, guest
    book, etc. all the way to about the most sophisticated thing you can
    imagine with a MySQL database (also open source software but extra
    charge to host). PERL is a lot more difficult to learn and use than PHP.
    Paul Furman, Feb 18, 2004
    #11

  12. >From:
    >
    >(Brett Baisley)
    >I have a web page that has html code that
    >I would like to add to every page
    >dynamically, instead of copying and
    >pasting it to every page. That way, when it
    >needs to be changed, it will be a lot less
    >work.


    Bottom line is... get with a host that supports SSI and hopefully uses
    Apache servers.... then you can take full advantage of using includes in
    your pages, and you can set up an .htaccess file so that you don't have
    to rename your pages to end in .shtml

    For more info, see SSI on the Menu on this page:
    http://davmagic.com/PAGES39.html

    And look here to learn how to set up and configure an .htaccess file for
    SSI:

    http://www.outfront.net/tutorials_02/adv_tech/htaccess_magic1.htm

    Web Design-Magic-Painting-Junking-Games
    http://www.davmagic.com
    Paint A House
    http://www.paintahouse.com
    Note: My email is ALWAYS Full to avoid SPAM... you can Contact me via my
    websites...
    Davmagic .Com, Feb 18, 2004
    #12
  13. Paul Furman wrote:

    > PERL is a lot more difficult to learn and use than PHP.


    I dunno. Perl isn't really that hard to learn. And once you understand the
    basics, it's very easy to solve big problems with just a few lines of Perl.

    I have written a graphical jukebox to play OGG files in 227 lines of Perl
    (excluding blank lines and comments).

    Simple Perl CGI example:


    ---------------------------------------
    #!/usr/bin/perl

    $date = `date -R`;
    $message = 'Hello World';

    print <<EOF;
    Content-Type: text/html

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <title>CGI Example</title>
    <p>The date is <b>$date</b> and my message is <i>$message</i>.</p>

    EOF
    ---------------------------------------

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
    Toby A Inkster, Feb 18, 2004
    #13
  14. Brett Baisley

    m Guest

    Toby A Inkster wrote:

    > Paul Furman wrote:
    >
    >> PERL is a lot more difficult to learn and use than PHP.

    >
    > I dunno. Perl isn't really that hard to learn. And once you understand the
    > basics, it's very easy to solve big problems with just a few lines of
    > Perl.


    Right. In general, Perl is easier to use than PHP after a short initial
    learning period. It blows away C++ and Java for any kind of
    administrative task. I think beginners panic seeing succinct markup like
    '$_' and '@_' ; but it saves so much irritating typing,
    and is actually not difficult to learn.

    And, after all the work w3c has done getting display and content
    seperated, why would anyone want to re-mud the waters by adding
    a bunch of coding into the middle of an (X)HTML page?
    --
    cheers m
    m, Feb 18, 2004
    #14
  15. Brett Baisley

    SpaceGirl Guest

    "Toby A Inkster" <> wrote in message
    news:p...
    > Paul Furman wrote:
    >
    > > PERL is a lot more difficult to learn and use than PHP.

    >
    > I dunno. Perl isn't really that hard to learn. And once you understand the
    > basics, it's very easy to solve big problems with just a few lines of

    Perl.
    >
    > I have written a graphical jukebox to play OGG files in 227 lines of Perl
    > (excluding blank lines and comments).
    >
    > Simple Perl CGI example:
    >
    >
    > ---------------------------------------
    > #!/usr/bin/perl
    >
    > $date = `date -R`;
    > $message = 'Hello World';
    >
    > print <<EOF;
    > Content-Type: text/html
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    > "http://www.w3.org/TR/html4/strict.dtd">
    > <title>CGI Example</title>
    > <p>The date is <b>$date</b> and my message is <i>$message</i>.</p>
    >


    <%
    myMessage = "Hello World"
    myDate = date
    myTime = time
    %>

    <p><%=message%></p>
    <p><%=myDate%></p>
    <p><%=myTime%></p>

    ASP is the easiest language on the planet. After all, it's BASIC :)
    SpaceGirl, Feb 18, 2004
    #15
  16. Brett Baisley

    Paul Furman Guest

    m wrote:
    > Toby A Inkster wrote:
    >
    >
    >>Paul Furman wrote:
    >>
    >>
    >>>PERL is a lot more difficult to learn and use than PHP.

    >>
    >>I dunno. Perl isn't really that hard to learn. And once you understand the
    >>basics, it's very easy to solve big problems with just a few lines of
    >>Perl.

    >
    >
    > Right. In general, Perl is easier to use than PHP after a short initial
    > learning period. It blows away C++ and Java for any kind of
    > administrative task. I think beginners panic seeing succinct markup like
    > '$_' and '@_' ; but it saves so much irritating typing,
    > and is actually not difficult to learn.
    >
    > And, after all the work w3c has done getting display and content
    > seperated, why would anyone want to re-mud the waters by adding
    > a bunch of coding into the middle of an (X)HTML page?


    PHP has a tremendous amount of pre-built functions that come out of the
    box for web related things like cookies and sessions. It's my
    understanding that Perl can be a lot of work to do things that are
    one-step in PHP. I'm pretty new to it though & don't know anything about
    Perl. I think PHP is considered a sloppy language that is not as precise
    but I appreciate that as someone who is not primarily (or hardly) a
    programmer.
    Paul Furman, Feb 18, 2004
    #16
  17. SpaceGirl wrote:

    > <%
    > myMessage = "Hello World"
    > myDate = date
    > myTime = time
    > %>
    >
    > <p><%=message%></p>
    > <p><%=myDate%></p>
    > <p><%=myTime%></p>
    >
    > ASP is the easiest language on the planet. After all, it's BASIC :)


    It's almost exactly the same in PHP:

    <?
    $myMessage = "Hello World";
    $myDate = date("d-m-y");
    $myTime = date("H:i:s");
    ?>

    <p><?= $message ?></p>
    <p><?= $myDate ?></p>
    <p><?= $myTime ?></p>

    However, ASP gets complicated very quickly. For example, today I needed to
    write an ASP (VB)script to list the files in a directory ("/uploads") on
    the webserver, not knowing the absolute path to the directory.

    I had to use this code:

    <%
    Dim objFSO, objFolder, objFile, f
    Response.ContentType = "text/plain"
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    f = Server.MapPath("/uploads")
    Set objFolder = objFSO.GetFolder(f)
    For Each objFile in objFolder.Files
    Response.Write objFile.Name & Chr(13) & Chr(10)
    Next
    %>

    Whereas in Perl I could have just done:

    #!/usr/bin/perl
    print "Content-Type: text/plain\n\n";
    system("ls -1 uploads");

    Easy peasy.

    PHP would be just as easy:

    <?
    header('Content-Type: text/plain');
    print `ls -1 uploads`;
    ?>

    Perl makes easy things easy and hard things possible. VBscript tends to
    make easy things easy and moderately complicated things unthinkable.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
    Toby A Inkster, Feb 18, 2004
    #17
  18. Brett Baisley

    m Guest

    Paul Furman wrote:

    >
    > m wrote:
    >> Toby A Inkster wrote:
    >>
    >>
    >>>Paul Furman wrote:
    >>>
    >>>
    >>>>PERL is a lot more difficult to learn and use than PHP.
    >>>
    >>>I dunno. Perl isn't really that hard to learn. And once you understand
    >>>the basics, it's very easy to solve big problems with just a few lines of
    >>>Perl.

    >>
    >>
    >> Right. In general, Perl is easier to use than PHP after a short initial
    >> learning period. It blows away C++ and Java for any kind of
    >> administrative task. I think beginners panic seeing succinct markup like
    >> '$_' and '@_' ; but it saves so much irritating typing,
    >> and is actually not difficult to learn.
    >>
    >> And, after all the work w3c has done getting display and content
    >> seperated, why would anyone want to re-mud the waters by adding
    >> a bunch of coding into the middle of an (X)HTML page?

    >
    > PHP has a tremendous amount of pre-built functions that come out of the
    > box for web related things like cookies and sessions. It's my
    > understanding that Perl can be a lot of work to do things that are
    > one-step in PHP.


    use CGI ':standard';
    # Above single line turns Perl into a web language.
    # The CGI module has everything you need to do web stuff
    # easily. But, no, you wouldn't want to write it from
    # scratch instead of including the module! Other modules
    # let you turn Perl into web robots, mail clients, and such --
    # all in the same program if you want!.

    print "Set-Cookie: zot=$zip;expires=30-Feb-2004 00:00:00 GMT\n";
    # ...and the above line sets a cookie with an expiration date.
    # That's all there is to it. Reading them is just as easy.
    --
    cheers m
    m, Feb 18, 2004
    #18
  19. On Tue, 17 Feb 2004 23:32:26 +0000, Brett Baisley wrote:

    > Any way to get this to work with just pure HTML? I found that I can include
    > a html file into another one, but then I'd have to change it to .shtml,
    > which doesn't work well here for some reason.



    While pure HTML won't work, you *can* configure the web server (Apache,
    say) to process .html files for SSI.

    Example (this goes inside httpd.conf):

    #
    # To use server-parsed HTML files
    #
    AddType text/html .shtml .html .booger
    AddHandler server-parsed .shtml .html .booger

    # There, I just configured Apache to process all *.booger files as
    # SSI files, as well as .html *and* .shtml

    Note: Parsing *every* .html file will, however, add overhead and will slow
    down the server a smidge. But not much.

    --
    -------------------------
    | Jeffrey Silverman |
    | jeffrey-AT-jhu-DOT-edu|
    -------------------------
    Jeffrey Silverman, Feb 19, 2004
    #19
  20. On Wed, 18 Feb 2004 20:58:46 -0000, "SpaceGirl"
    <> wrote:

    >
    >"Toby A Inkster" <> wrote in message
    >news:p...
    >> Paul Furman wrote:
    >>
    >> > PERL is a lot more difficult to learn and use than PHP.

    >>
    >> I dunno. Perl isn't really that hard to learn. And once you understand the
    >> basics, it's very easy to solve big problems with just a few lines of

    >Perl.
    >>
    >> I have written a graphical jukebox to play OGG files in 227 lines of Perl
    >> (excluding blank lines and comments).
    >>
    >> Simple Perl CGI example:
    >>
    >>
    >> ---------------------------------------
    >> #!/usr/bin/perl
    >>
    >> $date = `date -R`;
    >> $message = 'Hello World';
    >>
    >> print <<EOF;
    >> Content-Type: text/html
    >>
    >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    >> "http://www.w3.org/TR/html4/strict.dtd">
    >> <title>CGI Example</title>
    >> <p>The date is <b>$date</b> and my message is <i>$message</i>.</p>
    >>

    >
    ><%
    >myMessage = "Hello World"
    >myDate = date
    >myTime = time
    >%>
    >
    ><p><%=message%></p>
    ><p><%=myDate%></p>
    ><p><%=myTime%></p>


    I understand that handling file uploads requires a third-party
    component in ASP. PHP makes handing file uploads trivial.

    For sending e-mail, just use PHP's mail() function. That literally
    could not be easier!

    ASP is okay, but PHP is better ;-)

    --
    David ( @priz.co.uk )
    David Mackenzie, Feb 19, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Meade

    reusing a bit of code?

    Rob Meade, Jan 30, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    338
    Kevin Spencer
    Jan 30, 2004
  2. - Steve -

    Reusing Code Snippets

    - Steve -, Sep 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    408
    Greg Burns
    Oct 1, 2004
  3. Zodiac

    Reusing Code

    Zodiac, Feb 9, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    409
    Kevin Spencer
    Feb 9, 2005
  4. Oleg  Paraschenko
    Replies:
    0
    Views:
    366
    Oleg Paraschenko
    Jun 6, 2005
  5. Robin Forster

    reusing super class constructor code

    Robin Forster, Jun 28, 2003, in forum: C++
    Replies:
    7
    Views:
    5,423
    Dhruv
    Jun 29, 2003
Loading...

Share This Page