Thread: [htmltmpl] placing .tmpl files in a subdirectory?
Brought to you by:
samtregar
From: Will <sel...@ya...> - 2002-07-02 19:39:57
|
Greets Folks, Does anyone here place their .tmpl files in a special directory assigned just for templates, like maybe: /cgi-bin/templates I was thinking of doing this for organizational purposes, but I wasn't sure of what problems I might run into, or what path I would have to use in the CGI programs, etc... Any advice appreciated. Thanks, Will __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com |
From: Sam T. <sa...@tr...> - 2002-07-02 19:51:49
|
On Tue, 2 Jul 2002, Will wrote: > Does anyone here place their .tmpl files in a special > directory assigned just for templates, like maybe: > > /cgi-bin/templates > > I was thinking of doing this for organizational > purposes, but I wasn't sure of what problems I might > run into, or what path I would have to use in the CGI > programs, etc... Yes. If you do that, just use the path option to specify the path to the templates: my $t = HTML::Template->new(filename => 'foo.tmpl', path => 'templates'); -sam |
From: Douglas K. <dlk...@rh...> - 2002-07-02 21:11:54
|
On Tuesday 02 July 2002 10:51 am, Sam Tregar wrote: > On Tue, 2 Jul 2002, Will wrote: > > Does anyone here place their .tmpl files in a special > > directory assigned just for templates, like maybe: > > > > /cgi-bin/templates > > > > I was thinking of doing this for organizational > > purposes, but I wasn't sure of what problems I might > > run into, or what path I would have to use in the CGI > > programs, etc... > > Yes. If you do that, just use the path option to specify the path to the > templates: > > my $t = HTML::Template->new(filename => 'foo.tmpl', > path => 'templates'); > Ok I am curious, Can I do the following. This way I can have the template name that is assocated with the script and at the same level as the script directory. All the while not having to modify the following line. I would like it to be a cut and paste into each script. my $t = HTML::Template->new(filename => $0.'.tmpl', path => '../templates'); -- Douglas Kirkland Technical Support Department Rhyton Corporation te...@rh... http://www.rhyton.com |
From: Roger B. W. <ro...@fi...> - 2002-07-02 21:21:34
|
On Tue, Jul 02, 2002 at 02:10:58PM -0700, Douglas Kirkland wrote: >Ok I am curious, Can I do the following. This way I can have the template >name that is assocated with the script and at the same level as the script >directory. All the while not having to modify the following line. I would >like it to be a cut and paste into each script. Yes, though what I do is: my $fn=$0; $fn =~ /\/([^\/]*?)\.cgi$/; $fn="$1.tmpl"; &set_env; my $tmpl=HTML::Template->new(filename => $fn, die_on_bad_params => 0); where &set_env sets the HTML_TEMPLATE_ROOT. The directory structure is: cgi-bin/ a.cgi b.cgi etc. templates/ a.tmpl b.tmpl etc. Roger |
From: Philip S T. <phi...@gm...> - 2002-07-03 04:47:25
|
On Tue, 2 Jul 2002, Douglas Kirkland wrote: > Ok I am curious, Can I do the following. This way I can have the > template name that is assocated with the script and at the same level > as the script directory. All the while not having to modify the > following line. I would like it to be a cut and paste into each > script. > > > my $t = HTML::Template->new(filename => $0.'.tmpl', > path => '../templates'); > why not do this: my $t = new HTML::Template(filehandle => *DATA); then, you just put your template in the source file itself, either after __DATA__ or after __END__ |
From: Roy R. <ro...@ir...> - 2002-07-03 05:13:08
|
> On Tue, 2 Jul 2002, Douglas Kirkland wrote: > > > Ok I am curious, Can I do the following. This way I can have the > > template name that is assocated with the script and at the same level > > as the script directory. All the while not having to modify the > > following line. I would like it to be a cut and paste into each > > script. > > > > > > my $t = HTML::Template->new(filename => $0.'.tmpl', > > path => '../templates'); > > > > why not do this: > > my $t = new HTML::Template(filehandle => *DATA); > > then, you just put your template in the source file itself, either after > __DATA__ or after __END__ > > > Can you provide a more detailed example Thanks. Roy |
From: Philip S T. <phi...@gm...> - 2002-07-03 05:34:48
|
On Tue, 2 Jul 2002, Roy Rubin wrote: > > my $t = new HTML::Template(filehandle => *DATA); > > > > then, you just put your template in the source file itself, either after > > __DATA__ or after __END__ > > > > Can you provide a more detailed example well, I've never tried it myself, but it would look something like this: #!/usr/bin/perl -w use strict; use HTML::Template; my $t = new HTML::Template(filehandle => *DATA); # do normal template processing here __DATA__ <html> <head><title><tmpl_var title></title></head> <body> <h1><tmpl_var title></h1> <p> Hello <tmpl_var name>. </p> </body> </html> |
From: Kenny S. <ke...@jo...> - 2002-07-03 06:54:18
|
> why not do this: > > my $t = new HTML::Template(filehandle => *DATA); > > then, you just put your template in the source file itself, either after > __DATA__ or after __END__ But... that goes against everything that HTML::Template stands for, imo. The separation of program from display.. the ability to change the look without editing the source, etc. Kenny Smith JournalScape.com |
From: Philip S T. <phi...@gm...> - 2002-07-03 07:35:49
|
On Tue, 2 Jul 2002, Kenny Smith wrote: > > my $t = new HTML::Template(filehandle => *DATA); > > > > then, you just put your template in the source file itself, either after > > __DATA__ or after __END__ > > But... that goes against everything that HTML::Template stands for, > imo. The separation of program from display.. the ability to change > the look without editing the source, etc. true, but there is that small percent of web site hosting companies that don't let you keep files outside your document root - and you really don't want your templates read by everyone. besides, what you can really do, is get your templates designed separately, and then just copy then into the bottom of your file before deployment. like I said though, I've never done that. Philip |
From: John B. <joh...@ya...> - 2002-07-03 12:01:50
|
To stir the pot a bit: If you're going to put the template in the same file as your code, you might as well forget HTML::Template altogether and just print out your page with a "print <<HERE;" statement and embedded variables. It amounts to the same concept: first you prepare your substitution data, then you print the page making the substitutions. And the print version is more versatile, although less maintainable. - John --- Philip S Tellis <phi...@gm...> wrote: > On Tue, 2 Jul 2002, Kenny Smith wrote: > > > > my $t = new HTML::Template(filehandle => *DATA); > > > > > > then, you just put your template in the source > file itself, either after > > > __DATA__ or after __END__ > > > > But... that goes against everything that > HTML::Template stands for, > > imo. The separation of program from display.. the > ability to change > > the look without editing the source, etc. > > true, but there is that small percent of web site > hosting companies that > don't let you keep files outside your document root > - and you really > don't want your templates read by everyone. > > besides, what you can really do, is get your > templates designed > separately, and then just copy then into the bottom > of your file before > deployment. > > like I said though, I've never done that. > > Philip ===== "Now it's over, I'm dead, and I haven't done anything that I want; or, I'm still alive, and there's nothing I want to do." - They Might Be Giants, http://www.tmbg.com __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com |
From: Roy R. <ro...@ir...> - 2002-07-02 19:57:12
|
> > Greets Folks, > > Does anyone here place their .tmpl files in a special > directory assigned just for templates, like maybe: > > /cgi-bin/templates > > I was thinking of doing this for organizational > purposes, but I wasn't sure of what problems I might > run into, or what path I would have to use in the CGI > programs, etc... > > Any advice appreciated. > > Thanks, > > Will > I usually place the files under the HTML main directory under a templates folder. There are no problems at all, and the files could be placed anywhere. Roy ro...@ir... |
From: Kenny S. <ke...@jo...> - 2002-07-02 19:57:28
|
Hi Will, Yes, I put all of my templates in a subdirectory. You can set $ENV{'HTML_TEMPLATE_ROOT'} to the name of the subdirectory, and then just do $template = HTML::Template->new( filename => 'filename.tmpl' ) ; and H::T will look for $ENV{'HTML_TEMPLATE_ROOT'}/filename.tmpl Hope this helps, Kenny Smith JournalScape.com > Greets Folks, > > Does anyone here place their .tmpl files in a special > directory assigned just for templates, like maybe: > > /cgi-bin/templates > > I was thinking of doing this for organizational > purposes, but I wasn't sure of what problems I might > run into, or what path I would have to use in the CGI > programs, etc... > > Any advice appreciated. > > Thanks, > > Will |
From: Keith J. <kja...@ey...> - 2002-07-02 21:23:48
|
What we do is to place them in a directory at the same level as docroot and cgi-bin in a directory called templates. During development, we have a secondary docroot set up point to that directory so the designers can see the templates in a browswer. When we go to production, the secondary docroot is dropped. We also duplicate the directory structure under the templates directory to match as closely as we can the directory structuce of the cgi-bin directory to make maintenance easier. This doesn't always work out, but for the most part it does. We also place the name of the template in a comment at the top of each template so the template can be identified from a browser. Otherwise we would have to trace back through perl code to know which template is being used. Again, it makes maintenace much easier. Hope this helps. Keith Jackson On Tue, 2002-07-02 at 15:39, Will wrote: > Greets Folks, > > Does anyone here place their .tmpl files in a special > directory assigned just for templates, like maybe: > > /cgi-bin/templates > > I was thinking of doing this for organizational > purposes, but I wasn't sure of what problems I might > run into, or what path I would have to use in the CGI > programs, etc... > > Any advice appreciated. > > Thanks, > > Will > > > > __________________________________________________ > Do You Yahoo!? > Sign up for SBC Yahoo! Dial - First Month Free > http://sbc.yahoo.com > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Cory T. <ct...@on...> - 2002-07-02 22:03:06
|
> -----Original Message----- > From: htm...@li... > [mailto:htm...@li...]On Behalf Of > Keith Jackson > Sent: Tuesday, July 02, 2002 5:24 PM > To: Will > Cc: HTML Template > Subject: Re: [htmltmpl] placing .tmpl files in a subdirectory? > Just to add my method : > > What we do is to place them in a directory at the same level as docroot > and cgi-bin in a directory called templates. We store them outside of 'cgi-bin' and in fact, outside of the server_root altogether. We use a five-level deep structure of directories to store our templates : user's role templates, component (single-cgiapp), application (group-of-cgiapp), overall system templates, overall component templates. The bottom three levels ( role, component, application ) could contain a very flexible interface for a single application. The same application could exist solely using the top two levels ( system, component .) We also load all of our templates via an Abstract Factory pattern ( implemented as 'load_tmpl( )' in CGI::Application. ) This way the arguments passed to 'HTML::Template->new( )' are consistent and we can generate a new hierarchy from the configuration of the environment when a template is requested. Our structure is this way because we are deploying many copies of the same component with different interfaces (HTML::Templates,) and thus, we need a way to put custom HTML::Template files where needed but always be able to reuse the templates that were not changed. If a group of cgi::applications all use a template with the same name / functionality (a function of cgi::app design I guess) then a single template at application (group of cgi::app) can update multiple cgi::app interfaces (assuming the cgi::app in question did not further override the template.) Overriding 'load_tmpl( )' for cgi::application and using that to create html::template objects helped our design remain flexible MANY times. Even if I was not using CGI::application I would still strongly suggest an Adapter function of some type to ensure that updating your method for creating html::templates never becomes a chore. Just our method, Cory > > During development, we have a secondary docroot set up point to that > directory so the designers can see the templates in a browswer. When we > go to production, the secondary docroot is dropped. > > We also duplicate the directory structure under the templates directory > to match as closely as we can the directory structuce of the cgi-bin > directory to make maintenance easier. This doesn't always work out, but > for the most part it does. > > We also place the name of the template in a comment at the top of each > template so the template can be identified from a browser. Otherwise we > would have to trace back through perl code to know which template is > being used. Again, it makes maintenace much easier. > > Hope this helps. > > Keith Jackson > > On Tue, 2002-07-02 at 15:39, Will wrote: > > Greets Folks, > > > > Does anyone here place their .tmpl files in a special > > directory assigned just for templates, like maybe: > > > > /cgi-bin/templates > > > > I was thinking of doing this for organizational > > purposes, but I wasn't sure of what problems I might > > run into, or what path I would have to use in the CGI > > programs, etc... > > > > Any advice appreciated. > > > > Thanks, > > > > Will |
From: Roy R. <ro...@ir...> - 2002-07-02 21:47:20
|
> Greets Folks, > > Does anyone here place their .tmpl files in a special > directory assigned just for templates, like maybe: > > /cgi-bin/templates > > I was thinking of doing this for organizational > purposes, but I wasn't sure of what problems I might > run into, or what path I would have to use in the CGI > programs, etc... > > Any advice appreciated. > > Thanks, > > Will We usually separate the template names and location to a configuration file, which the designers can update on their own. It look something like this: TemplateConfig.pm ================== package TemplateConfig; use vars '$AUTOLOAD'; sub new { my $class = shift; bless { _base_template_path => '/path/to/files/templates', _add_rec => 'emp_add.html', _delete_rec => 'emp_delete.html', _edit_rec => 'emp_edit.html' }, $class; } sub AUTOLOAD { my ($self) = @_; $AUTOLOAD =~ /.*::get(_\w+)/; exists $self->{$1}; return $self->{$1}; } 1; In the cgi script, the package is instantiated and the file names are used in the following format: use TemplateConfig; $config = TemplateConfig->new(); $filename = $config->get_base_template_path . $config->get_add_rec Roy ro...@ir... |