I am trying to get some basic knowledge and experience with programming
mod_perl. I have created an HTML form that calls a perl script, get the
info, query a mySQL database and display the results. So far so good. I
am now trying to 'jazz-up' my results document with a CSS. I don't get
any errors but it just doesn't seem to work. Here is part of my perl
script that gets the user data and accesses the DB and generates the
document.
use CGI;
use DBI;
my $query=new CGI;
....
# output a document
print $query->header();
print $query->start_html(-title=>"Howdy",
-style=>{-src=>'./dynamic.css'});
print $query->h1('Form Data');
Here is the contents of the file dynamic.css, which I located in the
cgi-bin directory, which is where the perl script is also located.
h1 {
color: green;
}
Not much but it should prove a point (to me). I expect that the h1 'Form
Data' should be green, but it displays black.
I have been reading the doc for CGI.pm, specifically the section titled
'Limited support for Cascading Style Sheets'. I must have made an error
but I can't understand where. I tried changing the print h1 to print
$query->h1({-class=>'st1'}, 'Form Data'); and the style sheet to
h1.st1{...} but that didn't seem to make any difference.
I would appreciate all pointers (or references)!
TIA,
Chuck
Re: problem with CSS in a dynamic document
am 25.09.2009 14:26:27 von Gucheng.Ye
2009/9/25 Chuck Crisler :
>
> use CGI;
> use DBI;
>
> my $query=3Dnew CGI;
> ...
> # output a document
> print $query->header();
> print $query->start_html(-title=3D>"Howdy",
> Â Â Â Â Â Â Â Â Â Â =C2=
=A0 Â -style=3D>{-src=3D>'./dynamic.css'});
> print $query->h1('Form Data');
>
>
> Here is the contents of the file dynamic.css, which I located in the
> cgi-bin directory, which is where the perl script is also located.
>
You may want to put dynamic.css into apache's document directory
(/path/apache/htdocs) and change the corresponding line to:
-style=3D>{-src=3D>'/dynamic.css'});
All files under cgi-bin are tried to executed by apache.
Re: problem with CSS in a dynamic document
am 25.09.2009 14:48:06 von Chuck Crisler
PERFECT! :-) Thank You!!!
On Fri, 2009-09-25 at 20:26 +0800, å¶å¤å wrote:
> 2009/9/25 Chuck Crisler :
> >
> > use CGI;
> > use DBI;
> >
> > my $query=new CGI;
> > ...
> > # output a document
> > print $query->header();
> > print $query->start_html(-title=>"Howdy",
> > -style=>{-src=>'./dynamic.css'});
> > print $query->h1('Form Data');
> >
> >
> > Here is the contents of the file dynamic.css, which I located in the
> > cgi-bin directory, which is where the perl script is also located.
> >
>
> You may want to put dynamic.css into apache's document directory
> (/path/apache/htdocs) and change the corresponding line to:
>
> -style=>{-src=>'/dynamic.css'});
>
> All files under cgi-bin are tried to executed by apache.
Also, not to confuse you too much, but most people don't use CGI.pm's
HTML generation features any more. Most of us have moved on to using
HTML templates which makes it even easier to separate things out. And
it's more like editing a normal HTML file which is what most designers
are familiar with.
You should check out Template Toolkit
(http://search.cpan.org/perldoc?Template) or HTML::Template
(http://search.cpan.org/perldoc?HTML::Template).
--
Michael Peters
Plus Three, LP
Re: problem with CSS in a dynamic document
am 25.09.2009 18:04:14 von Bruce Johnson
On Sep 25, 2009, at 6:14 AM, Michael Peters wrote:
> On 09/25/2009 08:17 AM, Chuck Crisler wrote:
>
>> # output a document
>> print $query->header();
>> print $query->start_html(-title=>"Howdy",
>> -style=>{-src=>'./dynamic.css'});
>> print $query->h1('Form Data');
>
> Also, not to confuse you too much, but most people don't use
> CGI.pm's HTML generation features any more. Most of us have moved on
> to using HTML templates which makes it even easier to separate
> things out. And it's more like editing a normal HTML file which is
> what most designers are familiar with.
>
> You should check out Template Toolkit (http://search.cpan.org/perldoc?Template
> ) or HTML::Template (http://search.cpan.org/perldoc?HTML::Template).
or just print the html. When executed as a cgi script, the outgoing
connection from Apache is the script's stdout. Variables substitute
just fine.
print <
Content-type: text/html\n\n
Howdy $username!
....
EOF
Works for us.
This way I can do large swaths of straight html code without any
issue, and no potential complications from added modules.
I can also split the raw html into pieces so I can insert dynamically
created tables, etc.
I've used this to output pre-encoded rtf with variable substitution,
too.
(Hint, use Windows Write to generate the RTF, it makes simple, easy to
parse and customize rtf files. The RTF emitted by Word or TextEdit is
ginormously complicated)
--
Bruce Johnson
University of Arizona
College of Pharmacy
Information Technology Group
Institutions do not have opinions, merely customs
Re: problem with CSS in a dynamic document
am 25.09.2009 18:15:05 von Gucheng.Ye
2009/9/26 Bruce Johnson :
>
> or just print the html. When executed as a cgi script, the outgoing
> connection from Apache is the script's stdout. Variables substitute just
> fine.
>
> print <
> Content-type: text/html\n\n
>
>
> Howdy $username!
> ...
>
> EOF
>
> Works for us.
>
> This way I can do large swaths of straight html code without any issue, and
> no potential complications from added modules.
>
printing html directly in CGI scripts is maybe convenient for a small
application.
but, its maintainability is worse when the project is increasing.
I may think also using a template is better, that make perl code
separated from front-end codes (html/js/css etc), and make both perl
programmer and designer happy.
I personally prefer Template::Toolkit for CGI and Mason for mod_perl.
//yegucheng
Re: problem with CSS in a dynamic document
am 26.09.2009 16:49:36 von Chuck Crisler
I would like to thank everyone for the very useful information. I have
gotten everything to work well. Also, the diverse views have given me
more options to try.
I am new to this 'web thing', having done system level programming for
over 30 years. I am trying to learn the various strategies and the
strengths/weaknesses of the various technologies. I am currently
implementing a small-ish project for myself and will explore using PHP
and then PHP/Drupal on this project. I would really appreciate it if
people would comment on their views of these differing technologies,
what project types they are appropriate for and their experiences with
them or tell me where I can find these discussions on the web. I can see
some differences but until you have worked with them on a large project
it is really difficult to know the pitfalls. Please feel free to email
me directly rather than the full email list.
Again, thank you for your help!
Chuck
On Sat, 2009-09-26 at 00:15 +0800, å¶å¤å wrote:
> 2009/9/26 Bruce Johnson :
>
> >
> > or just print the html. When executed as a cgi script, the outgoing
> > connection from Apache is the script's stdout. Variables substitute just
> > fine.
> >
> > print <
> > Content-type: text/html\n\n
> >
> >
> > Howdy $username!
> > ...
> >
> > EOF
> >
> > Works for us.
> >
> > This way I can do large swaths of straight html code without any issue, and
> > no potential complications from added modules.
> >
>
> printing html directly in CGI scripts is maybe convenient for a small
> application.
> but, its maintainability is worse when the project is increasing.
> I may think also using a template is better, that make perl code
> separated from front-end codes (html/js/css etc), and make both perl
> programmer and designer happy.
> I personally prefer Template::Toolkit for CGI and Mason for mod_perl.
>
> //yegucheng
Re: problem with CSS in a dynamic document
am 27.09.2009 10:45:02 von Lesley B
On Sat, Sep 26, 2009 at 12:15:05AM +0800, å¶å¤å wrote:
> 2009/9/26 Bruce Johnson :
>
> >
> > or just print the html. When executed as a cgi script, the outgoing
> > connection from Apache is the script's stdout. Variables substitute just
> > fine.
> >
> > print <
> > Content-type: text/html\n\n
> >
> >
> > Howdy $username!
> > ...
> >
> > EOF
> >
> > Works for us.
> >
> > This way I can do large swaths of straight html code without any issue, and
> > no potential complications from added modules.
> >
>
> printing html directly in CGI scripts is maybe convenient for a small
> application.
> but, its maintainability is worse when the project is increasing.
> I may think also using a template is better, that make perl code
> separated from front-end codes (html/js/css etc), and make both perl
> programmer and designer happy.
> I personally prefer Template::Toolkit for CGI and Mason for mod_perl.
+1 on TT2 for building sites generally,
I'm twiddling on the edges of mod_perl - I really should jump in some time.
I use TT2 in command line mode to build a mostly static site with one
cgi script which itself uses the TT2 component templates to build the form
and process it.
I've basically a banner image, horizontal menu, a content section and some
information in a footer. I am able to modify, say, the footer data site wide by
editing one file and re-running the sitebuilding script. After testing I can issue
the new build and the altered templates for use on the site. More dynamic content
will ensue on this site and I will probably want the speed that mod_perl brings.