[Catalyst] Re: Branding - or path prefix

luke saunders luke.saunders at gmail.com
Fri Aug 12 16:38:53 CEST 2005


Thanks for this. I was thinking about writing something that does a
similar thing, now I don't need to.

I think I'll probably change it to get the branding from the config
and then make it an actual Plugin. Hope you're okay with that.

-luke

On 8/12/05, Uwe Voelker <uwe.voelker at gmx.de> wrote:
> Hello,
> 
> > sub prepare_action {
> >     my ( $c, @rest ) = @_;
> >     my $r = $c->NEXT::prepare_action( @rest );
> >
> >     #-- this line cuts of the first arg and puts it in the stash
> >     $c->stash->{path_prefix} = shift @{ $c->request->args };
> >
> >     $c->log->debug( 'Prefix is ' . $c->stash->{path_prefix} );
> >     return $r;
> > }
> 
> I tried this suggestion, but it didn't work. But I came up with this:
> 
> my $default_branding = 'demo';
> my @all_brandings    = qw(demo blue red green);
> 
> sub prepare_path {
>      my $c = shift;
> 
>      $c->NEXT::prepare_path(@_);
> 
>      my $base = $c->req->base;
>      my $path = $c->req->path;
> 
>      my $branding = $default_branding;
>      my $brandings = join('|', @all_brandings);
>      if ($path =~ m!^($brandings)/!) {
>          $branding = $1;
>          $path =~ s!^$branding/!!;
>      }
>      $base .= $branding.'/';
> 
>      $c->req->base($base);
>      $c->req->path($path);
> 
>      $c->stash->{branding} = $branding;
> }
> 
> I use it and so far it works great :-)
> 
> 
> Bye, Uwe
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>



More information about the Catalyst mailing list