Andy,
I structure my templates like:
/[projectdir]/templates/modulename/*.tmpl
/[projectdir]/templates/modulename2/*.tmpl
Each module has a $modulename variable in it, so that load_tmpl()
automatically knows which directory to use when looking for templates.
Taking this a step further, I also have a data directory for each module,
something like:
/[projectdir]/data/modulename/*.csv, *.txt, *.xml, *.log, etc
where I can store module specific data files and not have to worry about
where they are. When my app starts up it automatically constructs
'templatedir' and 'datadir' params for me.
As for static pages, I usually use:
/[projectdir]/templates/modulename/static/*.html
and have a superclass run-mode called screen that essentially functions
like:
sub screen
{
my $self = shift;
my $cgi = $self->query();
my $t = HTML::Template->new_file
(
$cgi->param('page') . '.html',
path => $self->param('templatedir') . '/static/',
);
return $t->output();
}
So now from any module you could call
/cgi-bin/module.cgi?rm=screen&page=home and you would have the home page
returned. Obviously you could eliminate HTML::Template all together and just
open / output the contents of the file. You could also play around with
making screen your default run mode so that you could just call
/module.cgi?page=home or having your default run mode check for a 'page'
param and shuffle off to $self->screen() if one is found.
Anyways, hope that helps.
> I'm getting ready to start a fairly large project using CGI::App and I was
just wondering how some of the more experienced/knowledgeable people on this
list handle some issues.
>
> 1. if you are doing a project with a superclass and several modules, where
do you put your templates and how do you organize them? For instance, if
/home/ataylor is my home dir, do most people do something like
/home/ataylor/project/modules and /home/ataylor/project/templates and put
all the templates in one big directory?
>
> 2. for a large project, not all of the pages have to be dynamic obviously.
How do people deal with static pages that you want to still share the look
of your dynamic pages that you are using HTML::Template for? I was
considering creating a commandline tool to generate the static pages from
the HTML::Templates or creating a module just for serving static pages (not
that they would be static anymore) and wrapping the header and footer,
setting the title, etc. but each of these have downsides. How do the experts
do it?
>
> much thanks for any advice and I think the discussions on this list are
invaluable.
>
> ---------------------------------------------------------------------
> Web Archive: http://www.mail-archive.com/suppressed/
> http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
> To unsubscribe, e-mail: suppressed
> For additional commands, e-mail: suppressed
>
>
>
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.