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

I am trying to add a style sheet to my app. I thought that I could use:
my $q = $self->query; $q->start_html( -style=> { -type => 'text/css', -src=>'/styles/print.css', -rel => 'stylesheet', -media => 'all' } );
I tried it in cgiapp_prerun & cgiapp_postrun. No errors tho.

Replies are listed 'Best First'.
Re: cgi application & global style sheet
by rhesa (Vicar) on Mar 02, 2006 at 18:32 UTC
    you could do it in postrun:
    sub cgiapp_postrun { my ($self, $output_ref) = @_; my $q = $self->query; $$output_ref = $q->start_html( -style=> { -type => 'text/css', -src=>'/styles/print.css', -rel => 'stylesheet', -media => 'all' } ) . $$output_ref; }
      your example creates 2 headers
      <!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 rel="stylesheet" type="text/css" href="/styles/print.css" rel="s +tylesheet" media="all"/> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Maintain Users</title> </head> <body>
        only if you already generated one in your run mode, and you didn't say you did. either way, i don't think you should be using CGI for generating html, but instead start looking at using templates. See HTML::Template or the Template Toolkit for that.