[Catalyst] How to trail the .html files in my control

Brandon Black blblack at gmail.com
Fri Feb 17 17:07:45 CET 2006


On 2/17/06, Vidya Sagar <vsagarkola at gmail.com> wrote:
> hi all ,
>
>  in my template  i have written
> [%c.request.base%]/page/terms_conditions.html.
>
>
>  given below code is written in maypole can i use for catalyst .
>
>  if i use where  can i put this   in my shop.pm or Shop/V/TT.pm
>  sub parse_path {
>
>          my $self = shift;
>          # remove the trailing .html for any path other than starting with
> /page/
>          $self->{path} =~ s/\.html$// if $self->{path} !~ /^page\//;
>
>           $self->SUPER::parse_path(@_);
>
>  }
>
>  This is not the whole code but a part of it and here is my TT.pm
>
>  package Shop::V::TT;
>
>  use strict;
>  use base 'Catalyst::View::TT';
>
>  use HTML::Entities;
>
>  sub new {
>          my $self = shift;
>          $self->config->{WRAPPER}     = 'wrapper';
>          $self->config->{COMPILE_DIR} = '/var/www/Shop/ttc';
>          $self->config->{FILTERS}     = {html_entity =>
> \&Shop::V::TT::html_encode_entities},
>          $self->config->{CONTEXT} = undef;  # it will disable profiling of
> templates
>          $self->config->{ERROR} = 'error';
>          return $self->SUPER::new(@_);
>  }
>
>
> Now in my browser, whenever i connect to any link in my web page it is
> taking only html files, but my problem is that it should take  the  method
> which is in .pm file- as html file and direct to the concerned html file.
>
>  kindly please help me
>

I don't think you can do this in quite this way, seeing as TT doesn't
know anything about the individual html elements in the plaintext of
your Template and the paths you want to modify are not variables in
Catalyst code either, because they're hardcoded in the TT Template. 
You might be able to pull something off in your "end" Catalyst action
that uses a regex substitution on $c->request->body after TT is done
processing, but it would be an ugly hack and an ugly regex.

I'm assuming that what you're trying to accomplish is importing a
whole set of legacy TT templates for a site, and then convert them
one-by-one into Catalyst actions and preprend the [% c.request.base %]
to the links to that action when it has been converted (so that your
app can run half old-style and half new-style during the transition),
and you want to strip the '.html' part on the names which are Catalyst
actions?

If that's not the case, a better explanation of what you're
functionally trying to accomplish would help.  If that is the case, I
would suggest using a better approach, like perhaps removing the
'.html' manually when you add the [% c.request.base %].

Incidentlaly, you can use just [% base %], it's the same thing.

-- Brandon



More information about the Catalyst mailing list