[Catalyst] dir structure for template files

Bill Moseley moseley at hank.org
Thu Apr 20 01:57:37 CEST 2006


On Thu, Apr 20, 2006 at 01:20:09AM +0200, Daniel McBrearty wrote:
> I seem to remember reading on the list someone talking about "best practic"
> for this being that the dir structure of templates mirrors the that of the
> actions that they go with.

Then you don't have to set $c->stash->{template} for every action.

I use a custom TT view, and I have:

    $c->stash->{template} ||= $self->template_name($c);


sub template_name {
    my ( $self, $c ) = @_;

    my $extension = $self->config->{TEMPLATE_EXTENSION} || '.tt';
    my $template_suffix = delete $c->stash->{template_suffix} || '';
    return $c->action->reverse . $template_suffix . $extension;
}


> But I don't find the post back by searching. Am I right? I don't see any
> obvious advantage ... unless you have actions of same names under different
> controllers, which I'd probably try to avoid.

I have "list" "view" "edit" in many different controllers.  Seems
very likely that action names would be the same.

> and what about common included tenplates and so on? any big reason not to
> lump 'em all into one directory?

I have an "include" directory, but then have sub-directories within
there.  I also have a "page" directory that holds header, footer,
wrapper, and layout templates.  I have an "email" template that holds
templates for emails, and those also mirror the controller layout.
And so on.


-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list