Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

using a CSS style sheet in CGI

by Anonymous Monk
on Jun 17, 2006 at 17:02 UTC ( [id://555993]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Using the CGI.pm module I bumped into a question. Without printing start_html, is it possible to push a CSS style sheet onto it?

I am writing a small CGI script that will be an SSI include, meaning it will be loaded from a page. Now, I made a custom CSS for the script and am wondering how I can use it without reprinting the header causing issues on the main page?

Is it possible for an SSI to call it's own CSS without doing anything like this?

Replies are listed 'Best First'.
Re: using a CSS style sheet in CGI
by cees (Curate) on Jun 18, 2006 at 01:14 UTC

    You can use the Link function to generate CSS link tags.

    CGI::Link({ -rel => 'stylesheet', -type => 'text/css', -src => '/css/my.css', -media => 'all' });

    That will generate the following HTML:

    <link type="text/css" media="all" src="/ss/ss.css" rel="stylesheet" />

    These tags are supposed to go in the 'head' section of the page, but most browsers will load them anywhere they appear.

Re: using a CSS style sheet in CGI
by jdtoronto (Prior) on Jun 17, 2006 at 17:50 UTC
    Each page one header. Your only option to generating the header using CGI.pm is to put the CSS in the document header.

    Alternatively, you might consider using something like HTML::Template which can allow you to customise the header, push it into the tempalte, and the template can have includes in it as well. This may well be an easier and cleaner way of acheiving what you need.

    jdtoronto

Re: using a CSS style sheet in CGI
by davidrw (Prior) on Jun 17, 2006 at 18:18 UTC
    Look for "css" in the CGI docs (note the 'LIMITED SUPPORT FOR CASCADING STYLE SHEETS' section in the table of contents).. You can tell start_html to have an include for an external css file and/or directly include some css code:
    start_html( -title=>"Foo", -style=>{src=>'foo.css', -code=>"body {background-colo +r: #000000}" }, ),
      Without printing start_html ...
      The output of the CGI-script will be included somewhere on the page and the web-server will take care of the headers.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-12-06 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (45 votes). Check out past polls.