[Catalyst] Re: Branding - or path prefix
Uwe Voelker
uwe.voelker at gmx.de
Fri Aug 12 16:23:07 CEST 2005
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
More information about the Catalyst
mailing list