Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

problem with CSS in a dynamic document

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


charles.crisler at comcast

Sep 25, 2009, 5:17 AM

Post #1 of 8 (956 views)
Permalink
problem with CSS in a dynamic document

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


Gucheng.Ye at freenet

Sep 25, 2009, 5:26 AM

Post #2 of 8 (899 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

2009/9/25 Chuck Crisler <charles.crisler [at] comcast>:
>
> 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.


charles.crisler at comcast

Sep 25, 2009, 5:48 AM

Post #3 of 8 (902 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

PERFECT! :-) Thank You!!!

On Fri, 2009-09-25 at 20:26 +0800, 叶孤城 wrote:
> 2009/9/25 Chuck Crisler <charles.crisler [at] comcast>:
> >
> > 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.


mpeters at plusthree

Sep 25, 2009, 6:14 AM

Post #4 of 8 (905 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

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).

--
Michael Peters
Plus Three, LP


johnson at pharmacy

Sep 25, 2009, 9:04 AM

Post #5 of 8 (899 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

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 <<EOF;
Content-type: text/html\n\n
<html>
<link rel="stylesheet" href="./dynamic.css" type="text/css"
<title>Howdy $username!</title>
...
</html>
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


Gucheng.Ye at freenet

Sep 25, 2009, 9:15 AM

Post #6 of 8 (898 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

2009/9/26 Bruce Johnson <johnson [at] pharmacy>:

>
> 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 <<EOF;
> Content-type: text/html\n\n
> <html>
> <link rel="stylesheet" href="./dynamic.css" type="text/css"
> <title>Howdy $username!</title>
> ...
> </html>
> 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


charles.crisler at comcast

Sep 26, 2009, 7:49 AM

Post #7 of 8 (894 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

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 <johnson [at] pharmacy>:
>
> >
> > 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 <<EOF;
> > Content-type: text/html\n\n
> > <html>
> > <link rel="stylesheet" href="./dynamic.css" type="text/css"
> > <title>Howdy $username!</title>
> > ...
> > </html>
> > 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


lesleyb at pgcroft

Sep 27, 2009, 1:45 AM

Post #8 of 8 (885 views)
Permalink
Re: problem with CSS in a dynamic document [In reply to]

On Sat, Sep 26, 2009 at 12:15:05AM +0800, 叶孤城 wrote:
> 2009/9/26 Bruce Johnson <johnson [at] pharmacy>:
>
> >
> > 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 <<EOF;
> > Content-type: text/html\n\n
> > <html>
> > <link rel="stylesheet" href="./dynamic.css" type="text/css"
> > <title>Howdy $username!</title>
> > ...
> > </html>
> > 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.

Regards

L.

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.