Search code examples
perlcatalysttemplate-toolkit

How can I dynamically process all .html files through the Catalyst Framework?


I want to use Catalyst to process all requests: Both html (mixed with Template Toolkit), and those normally intended to be processed by Catalyst. I am aware of Catalyst::Plugin::Static::Simple, but that doesn't seem like it does what I am describing since it simply prints files statically.

As an example, I want to show whether the user is logged in on index.html without using ajax or SSI. There are many other cases beside that one.

There is probably a simple answer to this...


Solution

  • Thanks for the pointer, RET. My solution turned out to be pretty simple.

    I made the nginx config point to my Catalyst App before serving files directly and added the path to my html files to the TT config in myapp.pm.

    Here are the basics of the snippet I added to my Root.pm controller in the default subroutine:

    if($c->req->path =~ m{\.html$} || $c->req->path =~ m{\.htm$}) {
        $c->stash->{template} = $c->req->path;
        $c->detach;
    }
    elsif($c->req->path !~ m{[.]+}) {
        $c->stash->{template} = $c->req->path . '/index.html';
        $c->detach;
    
    }