Re: Perl + Dreamweaver?
- From: Fabian Pilkowski <pilkowsk@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 19 Apr 2005 18:31:09 +0200
* Nikos schrieb:
> Scott Bryce wrote:
>> Nikos wrote:
>>
>>> In your opinion whats the easiest way of creating a Perl CGI Webpage
>>> and why?
>>>
>>> Perl + cgi.pm ? (the way i have it now)
>>> Perl + Dreamweaver ?
>>> Perl + Style Sheets ?
>>
>> CGI.pm, DreamWeaver and CSS do three very different things. Use the ones
>> that do the job you want to do. You will probably wind up using all
>> three for different aspects of this task.
>
> One is enouph thank you! :-)
Please read carefully. They do *different* things, really. "Perl and
CGI.pm" is generating the output when someone requested your webpage via
browser. "Dreamweaver" could be used to generate HTML pages, but has
nothing to do with Perl (and I don't think, they could interact at all).
"Stylesheets" are used to separate layout and content inside a webpage.
Now, it's your part to choose what you want. After reading this thread
it seems like:
* use Dreamweaver to generate templates
* use Perl and HTML::Template to fill the templates with content
>
> Can you please give the simplest example on html::template?
Gunnar has given a simple example on HTML::Template. Nevertheless I can
give you a rewrite of it, just to see how it works -- perhaps this gives
you the point you don't understand yet. Assume this in mytemplate.html:
<html>
<head>
<title><tmpl_var name=header></title>
</head>
<body>
<h1><tmpl_var name=header></h1>
<p>
This is a <tmpl_var name=var1> for illustrating the
principles with a <tmpl_var name=var2>.
</p>
</body>
</html>
This is an example of template that HTML::Template needs to work. The
tags named <tmpl_var> are the variables which will be filled in by a
Perl sript later. It's your job to generate such templates, either by
type them by hand or by using Dreamweaver, you mentioned above. But this
newsgroup is not the right place to ask, how (or if?) Dreamweaver could
be used for this. However, after you have such an template, you can fill
it by using Perl.
#!/usr/bin/perl
use strict;
use warnings;
# You need CGI.pm, eg. to generate a valid header, perhaps you're
# doing some other stuff with it, like parsing parameters.
use CGI;
use CGI::Carp qw( fatalsToBrowser );
# You need HTML/Template.pm to process your template.
use HTML::Template;
# Declare the vars you want to put into your template, this could
# be easily done with a hash. In general, you get your values by
# calculating something, connecting to a database etc.
my %tmplvar = (
HEADER => 'My Template',
VAR1 => 'template',
VAR2 => 'templating system'
);
# Now, all needed vars are saved in the hash. It's time to read in
# the template file.
my $tmpl = HTML::Template->new( filename => 'mytemplate.html' );
# Fill in the template with your values, here we do this in one step
# by passing the whole hash to param(). Gunnar has shown how to set
# each var separately.
$tmpl->param( %tmplvar );
# The vars are determined, the template is filled with them -- let's
# write it out. First the header (as usual, you know?), followed by
# the template's output.
print CGI::header(), $tmpl->output;
__END__
If you ignore all my comments, it's not really a long perl script, isn't
it? But that's really all, you have to do (I know, I wrote it already):
* generating the template and
* fill in the template
Dreamweaver could help you to generate the templates (perhaps), and Perl
does help you to fill them with your content. The Perl modules »CGI« and
»HTML::Template« are just helping you with that. Sure, you could reject
this help and stick your own with an regex (Gunnar has done this in his
first code snippet), but I don't recommend that.
Last but not least, your templates could contains style sheets (CSS).
That's the usual way to reduce formatting directives in HTML (doesn't
matter if it is an template or not).
Hope this helps.
regards,
fabian
.
- Follow-Ups:
- Re: Perl + Dreamweaver?
- From: Nikos
- Re: Perl + Dreamweaver?
- References:
- Perl + Dreamweaver?
- From: Nikos
- Re: Perl + Dreamweaver?
- From: Lord0
- Re: Perl + Dreamweaver?
- From: Nikos
- Re: Perl + Dreamweaver?
- From: Gunnar Hjalmarsson
- Re: Perl + Dreamweaver?
- From: Nikos
- Re: Perl + Dreamweaver?
- From: Scott Bryce
- Re: Perl + Dreamweaver?
- From: Nikos
- Perl + Dreamweaver?
- Prev by Date: Re: Perl + Dreamweaver?
- Next by Date: Re: First Line of Code - perl via Windows
- Previous by thread: Re: Perl + Dreamweaver?
- Next by thread: Re: Perl + Dreamweaver?
- Index(es):
Loading