#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0

    Question Linking an external CSS stylesheet to a Perl generated HTML document


    G'day sports ...

    I've had a look-see on the internet for an answer to this, and I haven't found one yet, so maybe you can help. I have installed a guestbook at my site, which uses Perl (it was an 'off-the-shelf' one from here). The problem is that I can link the guestbook pages to the site stylesheet, but when you add to the guestbook it generates a very plain looking [i.e. unformatted] confirmation page that looks very out of place. My question is, therefore, how (and I'm assuming that it's possible) do you link a perl generated webpage to an external CSS document, so that it's formatted to look the same as the rest of the site?

    I am new to perl (i.e. have no knowledge of it), but would assume that the relevant part of the script involves the 'print' command. I don't have the script to hand, but the instructions are along a similar line to this ...

    PHP Code:
      print "Content-type: text/html\n\n";

       print 
    "<html>\n <head>\n  <title>Results of Search</title>\n </head>\n";

       print 
    "<body bgcolor=\"WHITE\">\n <center>\n  <h1>Results of Search in $title</h1>\n </center>\n";

       print 
    "Below are the results of your Search in no particular order:<p><hr size=7 width=75%><p>\n"
    ... and that the link to the external stylesheet would go in there somewhere. Any suggestions will be gratefully received, and aplogies if I'm missing anything obvious.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    136
    Rep Power
    12
    A link to an external stylesheet goes into the <head>, doesn't it? I would think that if you just put print in front of the necessary tags that specify the external stylesheet, then it should work, since it knows that it is html.

    Try putting the stylesheet reference into the appropriate place with the print command in front of it, it ought to work that way.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0
    Thanks for your reply. Y'know I actually think that I tried that, kinda like this ...

    PHP Code:
       print "Content-type: text/html\n\n";

       print 
    "<html>\n <head>\n  <title>Results of Search</title>\n </head>\n";

       print 
    "<link href=\"../beaver.css\" hreflang=\"en\" rel=\"stylesheet\" type=\"text/css\" charset=\"UTF-8\" >\n";

       print 
    "<body bgcolor=\"WHITE\">\n <center>\n  <h1>Results of Search in $title</h1>\n </center>\n";

       print 
    "Below are the results of your Search in no particular order:<p><hr size=7 width=75%><p>\n"
    ... but this made the script sick. Whenever I tried to add to the guestbook, it errored and informed me that I should contact the site administrator. Which is me, and I'm no use, I can tell you ...

    Before that, I had tried to insert the link to the CSS document in the <head></head> line above, as I would with a regular HTML document, but didn't work either. Any ideas?
  6. #4
  7. Y? Y!?
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2003
    Location
    Brisbane, Australia
    Posts
    1,573
    Rep Power
    49
    As Ex-RoNiN mentioned, the <link href...> tag needs to go in the <head> section (anywhere between <head> and </head>).

    Your code contains the css link after the head (</head>) tag, hence the errors you are getting.

    Also, use 'code' and '/code' tags around perl scripts rather than 'php' tags. Your script should be something along these lines...

    Code:
    print "Content-type: text/html\n\n";
    
    print "<html>\n <head>\n  <title>Results of Search</title>\n \n";
    
    print "<link href=\"../beaver.css\" hreflang=\"en\" rel=\"stylesheet\" type=\"text/css\" charset=\"UTF-8\" ></head>\n";
    
    print "<body bgcolor=\"WHITE\">\n <center>\n  <h1>Results of Search in $title</h1>\n </center>\n";
    
    print "Below are the results of your Search in no particular order:<p><hr size=7 width=75%><p>\n";
    Note the </head> tag after the css link.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0
    Thanks for that ... like I say I'm new to both perl and this board. I did try that originally, but it wasn't split over two lines (i.e. the css link didn't have a print command before it) - does this make a difference?
    If that is the definitive answer, I'll know that any further problem is likely to be syntax related ... is there anything like emacs for the windows o/s?
  10. #6
  11. Y? Y!?
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2003
    Location
    Brisbane, Australia
    Posts
    1,573
    Rep Power
    49
    Metatron - I'm not sure if you understood my last post.

    The css link in your code was placed after the </head> tag, whereas it should be placed between the <head> and </head> tag.

    NTEmacs and Crimson Editor are both OK for Windows. Do a Google search to find out about download options.
  12. #7
  13. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    The perl interpreter won't understand HTML so if you just type HTML code without a print statement, perl will try to execute it as Perl code and fail because it isn't valid.

    Originally posted by Metatron
    is there anything like emacs for the windows o/s?
    Not to be smart but there's an excellent program for Windows that's very similar to emacs. It's called emacs

    See here in the FAQ on how to obtain it.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0
    Heh ... my sister told me that emacs was for linux (another thing to get my head around) and that she didn't know of any authoring tools for windoze. And I believed her ... more fool me, eh?

    Thanx for the help, I appreciate it.
  16. #9
  17. Perl Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    May 2003
    Location
    the far end of town where the Grickle-grass grows
    Posts
    1,860
    Rep Power
    109
    UltraEdit, EditPlus, and TextPad are probably the three most popular windows text/code editors (that I've heard of). The nature of open source means that there's generally a windows port of any popular linux app, so emacs/jed/vi/vim are all around if you look.

    Also, you could use CGI.pm and generate more standard html (or go all the way up to HTML::Template).
    Code:
    use CGI qw/:standard/;
    
    print header(),
          start_html( -title   => 'Results of Search',
                      -head    => Link( { -href     => '../beaver.css',
                                          -hreflang => 'en',
                                          -rel      => 'stylsheet',
                                          -type     => 'text/css',
                                          -charset  => 'UTF-8' } ),
                      -bgcolor => 'white'),
          h1( { -style => 'text-align: center' }, 'stuff'),
          'Below are the results of your Search in no particular order:',
          p( hr( { -size => '7', width => '75%' } ) );
    Andrew - Perl (and VB.NET) Monkey

    Never underestimate the bandwidth of a hatchback full of tapes.
  18. #10
  19. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    Avoid relative paths ("../beaver.css") - what if you decide to move your script up or down the directory tree?

    I personally cannot think of a reason to use relative paths over absolute. . .
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    235
    Rep Power
    16
    Hero ZzYzzx wrote:

    I personally cannot think of a reason to use relative paths over absolute. . .
    I've come this problem. I use relative references. I test my webpages on a local server before uploading them. I would have to change every absolute reference to have it work... unless there's a way round it?

    Andy
    Time isn't wasted if you're wasted all the time
  22. #12
  23. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    Start a new thread. This is veering off topic.

    Can you give more details? Are you talking paths relative to your webroot (that used by your webserver) or relative to your OS- those that are actually on the filesystem?

IMN logo majestic logo threadwatch logo seochat tools logo