[Catalyst] Displaying template files without adding new controller actions

Fernan Aguero fernan.aguero at gmail.com
Tue Oct 12 16:29:13 GMT 2010


On Tue, Oct 12, 2010 at 1:27 PM, Fernan Aguero <fernan.aguero at gmail.com> wrote:
> On Tue, Oct 12, 2010 at 12:47 PM, Anthony Gladdish
> <a.j.gladdish at newcastle.ac.uk> wrote:
>> Thanks for your feedback Denny, Ben and Stuart – good food for thought!
>>
>> I think some sort of handling logic in Root’s default action to test for the
>> existence of template and error or 404 if it doesn’t – is the way forward.
>>
>> Many thanks,
>>
>> Anthony
>
> Indeed. We had the same itch, and in our app, what we did is the following:
>
> i) uniquely name all templates that need some processing by the
> templating engine (e.g. to apply headers or footers) but otherwise no
> processing by a controller. In our case all templates are named as
> *.tts files.

Errate: of course I meant 'all these templates' ... the rest of the
templates (those referred to by controllers) are of course named '.tt'
or '.tt2'

Cheers,

> Then in the Root.pm controller we have something like:
> sub default : Private {
>   my ( $self, $c ) = @_;
>
>   my $path = $c->request->path;
>   my $root = $c->config->{root};
>
>   if ( -e "$root/src/$path.tts" ) {
>     $c->stash->{template} = "$path.tts";
>    ...
>   ...


-- 
fernan



More information about the Catalyst mailing list