Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Included cgi does not get CSS formatted?

by Jman1 (Acolyte)
on Apr 07, 2009 at 00:53 UTC ( #755904=perlquestion: print w/ replies, xml ) Need Help??
Jman1 has asked for the wisdom of the Perl Monks concerning the following question:

RESOLVED: The problem was that I was doing

$c->start_td(-id=>'foo', -width=>'20', -valign=>'top'),

instead of

$c->start_td({-id=>'foo', -width=>'20', -valign=>'top'}),

The CSS must look for 'foo' and it didn't find it because the perl script was incorrect. It provided <td> instead of <td id="foo" etc>.

---------------------

I inherited a webpage which includes a .inc file. The resulting combination is somehow styled by a CSS file. It works great.

I want to change from the .inc file to a perl script so that it can change dynamically. I created a script which outputs exactly the same contents of the .inc file and included it by simply changing the line

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

with the line

<!--#include file="cgi-bin/bar.pl"-->

I'm using apache with server-side includes turned on.

Everything works perfectly except that no formatting is applied to the portion of the page which was previously described by the .inc file and now is created by the .pl file.

Any ideas? I've tried adding a link to the CSS file as a parameter to the the start_html method ('-type'=>'text/html', '-src' => '/css/foo.css'). I tried renaming the .pl to a .css. (Dumb idea, but worth a shot.)

Apologies if this is a dumb question. I've never used CSS before.

Comment on Included cgi does not get CSS formatted?
Select or Download Code
Re: Included cgi does not get CSS formatted?
by Anonymous Monk on Apr 07, 2009 at 01:10 UTC
    D:\>perl -MCGI -le"print CGI->start_html ('-type'=>'text/html', '-src' + => '/css/foo.css')" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <link rev="made" href="mailto:CGI" /> </head> <body src="/css/foo.css" type="text/html"> ^^^^^^^^^^^^^^^^^ |||||||||||||||||
    CGI: CREATING THE HTML DOCUMENT HEADER
    print start_html(-title=>'Secrets of the Pyramids', -author=>'fred@capricorn.org', -base=>'true', -target=>'_blank', -meta=>{'keywords'=>'pharaoh secret mummy', 'copyright'=>'copyright 1996 King Tut'}, -style=>{'src'=>'/styles/style1.css'}); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |||||||||||||||||||||||||||||||||||||
Re: Included cgi does not get CSS formatted?
by ww (Bishop) on Apr 07, 2009 at 02:18 UTC

    Assuming html 4.01 (loose or strict), your head section needs these:

    <meta http-equiv="Content-Style-Type" content="text/css"> <link rel="stylesheet" type="text/css" href="/css/foo.css">

    Note type is 'text/css', not 'text/html' (single or double quotes, your choice), and the link rel line, which you can do manually, or find the appropriate CGI method in the docs.

    You may gain more insight by reading the html in the .inc file or at w3c.org, w3cschools.org, etc.

      <meta http-equiv="Content-Style-Type" content="text/css">

      You only need this if you use the style attribute - and you are usually best off avoiding that in favour of real stylesheets.

      w3cschools.org

      W3Schools is unfortunately popular. It seems to get a lot of traffic by trading off the closeness of its name to that of the W3C and a significant number of people are surprised to find that they aren't the same organisation.

      Sadly, it is more than a little error prone and its examples have a tendency to run as far away from best practice as possible.

      The specifications at the W3C are good, and Opera has a good set of tutorials. I would suggest using these instead.

Re: Included cgi does not get CSS formatted?
by dorward (Curate) on Apr 07, 2009 at 08:51 UTC

    I think you are looking in the wrong place, at least for starting out.

    The browser is getting some HTML and (probably) CSS and rendering it, and it isn't rendering it the way you want.

    This means that the HTML and/or CSS is wrong.

    You are looking at the SSI and the Perl - but you should be looking at the HTML and CSS to see how they differ from what you want.

    Once you have figured out what is wrong with the HTML and/or CSS then you can worry about changing the Perl so it generates the HTML you actually want.

    Tools such as a validator might help you track down problems in the HTML, and…

    I've never used CSS before.

    Opera has a web standards tutorial that includes a decent section on CSS.

Re: Included cgi does not get CSS formatted?
by lostjimmy (Chaplain) on Apr 07, 2009 at 14:49 UTC

    With this being a SSI, you probably don't want to even call the start_html method. That is going to print new <html>, <body>, and <head> tags, which the main page most likely already has.

    The HTML page also probably already includes the style sheets. What you need in your perl script is some HTML that uses the classes in the already existing style sheets. What's confusing is that the .inc file worked correctly and your perl script isn't. What's the difference between the two?

    Also, if you can post a minimal example of what the HTML page and the perl script are doing, that might be helpful.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://755904]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-07-10 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (216 votes), past polls