[Catalyst] Where to put template files?

John Napiorkowski jjn1056 at yahoo.com
Thu Jun 8 11:59:25 CEST 2006


I'm not sure if you've gotten a good answer for this,
so here is my two cents:

If you just go with the default of not manually
setting the template with $c->stash->{template} = ''
then the TT view will look inside the root  directory
(the /root inside your catalyst app, not the OS root)
at a path that is based on your associated catalyst
action.

  So if you have a controller called 'test' and an
action inside it called 'hello' you should make a file
called 'hello' inside of the path 'root/test'.  That
'hello' file should be your template toolkit template.

If you use a regex or localregex then you use the
subroutine name:

package myapp::Controller::items;

sub item : Regex('/n/n/n/') { ... }

the default path is 'root/items/item'

You can overide the default path in the TT config.  I
did that for my first application but decided in the
end it's better to just go with the default and not
make my application 'too much of a individual
snowflake'.  Here is how you'd do that if you want to:

package talentspace_portal::View::tt_page;

use strict;
use warnings;

use base 'Catalyst::View::TT';

__PACKAGE__->config(

  INCLUDE_PATH	=> [talentspace_portal->path_to(
'tt_templates' ),],

  TEMPLATE_EXTENSION	=> '.tt',
  WRAPPER	=> 'page_wrapper.tt',
  PRE_PROCESS	=> '_macros/forms.tt',
  COMPILE_DIR	=> '/tmp/template_cache',

);	

It's that "INCLUDE_PATH" that is the relevant bit. 
That makes the path set to "[myapp_path]/tt_templates"
which is more neat than to throw everything into root.
 However if everyone expects to find stuff in root
maybe I'd rather not rock the boat just to make things
look neat to me :)

You might notice that the value of that key is a
reference to an array.  You can actually set multiply
paths if you want, although I don't know the potential
performance impact of that.  I can see that being
useful if you have several catalyst applications
running as part of the same system and you wanted to
share templates in a global area, as well as having
local templates.

BTW, that "TEMPLATE_EXTENSION" is very useful.  It
allows you to add whatever file association you want
to use for your template toolkit templates.  If you
have an editor that does color syntax based on the
file extension it could prove useful.

Hope this helps.  --john

--- Marcello Romani <mromani at ottotecnica.com> wrote:

> Kieren Diment ha scritto:
> > It's a good idea to change the subject of your
> mail, so that it doesn't 
> > get burried if you're reading the digest.  I don't
> know the answer to 
> > your question, but I'm reposting with a sensible
> subject for you instead
> > 
> > On 08/06/06, *Dr. Jennifer Nussbaum*
> <bg271828 at yahoo.com 
> > <mailto:bg271828 at yahoo.com>> wrote:
> > 
> > 
> > 
> >         You can do something like:
> > 
> > 
> >         SetHandler perl-script
> >         PerlResponseHandler MyApp
> > 
> >         Alias /myapp/static
> /path/to/myapp/root/static
> > 
> >         Order allow,deny
> >         Allow from all
> > 
> >         SetHandler default-handler
> > 
> >     Thank you!!!
> > 
> >     But one question--where do my templates go?
> Right now their under,
> >     lets say, /path/to/myapp/root/. And i dont
> want to change anything
> >     in MyApp.pm so i can
> >     keep running it with the builtin testing
> server.
> 
> If everything is working fine under the test server,
> then it should Just 
> Work (tm) under apache. Templates don't have to be
> moved.
> 
> > 
> >     The docs for Catalyst::View::TT talk about
> adding locations for the
> >     template root but they dont really say what
> the default location is.
> >     (It shows about havng MyApp->config({root =>
> >     MyApp->path_to('root')}) but right now i don't
> have that and things
> >     work fine with the test server.) Where should
> i put it all?
> > 
> >     Jen.
> > 
> >    
> __________________________________________________
> >     Do You Yahoo!?
> >     Tired of spam? Yahoo! Mail has the best spam
> protection around
> >     http://mail.yahoo.com
> > 
> > 
> >    
> _______________________________________________
> >     Catalyst mailing list
> >     Catalyst at lists.rawmode.org
> <mailto:Catalyst at lists.rawmode.org>
> >    
> http://lists.rawmode.org/mailman/listinfo/catalyst
> > 
> > 
> > 
> > 
> >
>
------------------------------------------------------------------------
> > 
> > _______________________________________________
> > Catalyst mailing list
> > Catalyst at lists.rawmode.org
> > http://lists.rawmode.org/mailman/listinfo/catalyst
> 
> 
> -- 
> Marcello Romani
> Responsabile IT
> Ottotecnica s.r.l.
> http://www.ottotecnica.com
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list