white-labelling [Catalyst]
James R. Leu
jleu at mindspring.com
Thu Jan 24 16:39:40 GMT 2008
Nice. I'm using a similar setup for my Model. It just never dawned
on me I could do that same for the View.
Thank you for the suggestion.
On Thu, Jan 24, 2008 at 10:12:56AM -0600, Jonathan Rockway wrote:
> "James R. Leu" <jleu at mindspring.com> writes:
>
> > I implemented this in Catalyst by modifying the View:TT path based on the
> > contents of $c->request->uri->host(). I'm sure this isn't revolutionary,
> > but for the sake of completeness and peer review ....
> >
> > Here is a trimmed down version of my MyApp::Controller::Root::auto()
> >
> > sub auto : Private {
> > my ($self, $c) = @_;
> >
> > my $hostMap = {
> > 'foo.example.com' => [ 'foo/lib', 'foo/src' ]
> > 'bar.example.com' => [ 'bar/lib', 'bar/src' ]
> > };
> >
> > my $server = $c->request->uri->host();
> > if (defined($hostMap->{$server})) {
> > my $path = [];
> > foreach my $elem (@{$hostMap->{$server}}) {
> > push(@{$path}, $c->config->{root} . '/' . $elem);
> > }
> > $c->stash->{additional_template_paths} = $path;
> > }
> >
> > ...
> > }
>
> This is nice, but I think I would have implemented this as 3 views:
>
> package View::Foo;
> use base 'TT'; # blah blah blah
> __PACKAGE__->config( INCLUDE => <the foo files> );
> 1;
>
> package View::Bar;
> use base 'TT'; # blah blah blah
> __PACKAGE__->config( INCLUDE => <the bar files> );
> 1;
>
> package View::TT;
>
> my %view_for = (
> 'foo.com' => sub { shift->view('Foo') },
> 'bar.com' => sub { shift->view('Bar') },
> );
>
> sub ACCEPT_CONTEXT {
> my ($self, $c) = @_;
> return ($view_for{$c->req->host} || die 'not found')->($c);
> }
> 1;
>
> Then in your app, you just say:
>
> $c->view('TT')
>
> and you get the correct view automatically.
>
> Code is untested, but the concept is.
>
> Regards,
> Jonathan Rockway
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
--
James R. Leu
jleu at mindspring.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080124/427d8e69/attachment.pgp
More information about the Catalyst
mailing list