FAQ
Hello Catalysters,

First of all thanks for the great work.

I've discovered Catalyst a few days ago,
but as I could'nt find a solution to my problem using the released code,
I think that the attached patch may be useful to others.
I'm currently porting a Apache/HTML::Mason Webapp to Catalyst,
and I need to do something like this :

all pages share the same global page template,
let's call it 'page.mason',
and it looks like this

( snip HTML & CSS begin code ... )
<body>
<div id="left_margin">
<% $c->stash->{left_margin} %>
</div>

<div id="center">
<% $c->stash->{center} %>
</div>

<div id="right_margin">
<% $c->stash->{right_margin} %>
</div>
( snip HTML end code ... )

$c->stash->{left_margin}, $c->stash->{center},
$c->stash->{right_margin}, etc
are set via the page Controller,
by rendering specific templates

package MyApp::C::MyPage;

use strict;
use base 'Catalyst::Base';

sub begin : Private {
my ( $self, $c ) = @_;
unless ($c->stash->{my_app_config}) {
$c->stash->{my_app_config} = MyApp::M::Config->getConfig;
}
$c->forward('center');
}

sub center : Private {
my ( $self, $c ) = @_;
$c->stash->{template} = 'mypage_center.mason';
$c->stash->{center} = $c->forward(qw/MyApp::V::Mason render/);
$c->forward('right_margin');
}

sub right_margin : Private {
my ( $self, $c ) = @_;
$c->stash->{template} = 'mypage_right.mason';
$c->stash->{right_margin} = $c->forward(qw/MyApp::V::Mason render/);
$c->forward('left_margin');
}

sub left_margin : Private {
my ( $self, $c ) = @_;
$c->stash->{template} = 'mypage_left.mason';
$c->stash->{left_margin} = $c->forward(qw/MyApp::V::Mason render/);
}

sub default : Private {
my ( $self, $c ) = @_;
$c->stash->{template} = 'page.mason';
$c->stash->{title} = "My page";
$c->forward('MyApp::V::Mason');
}

I had to use a new method, because Catalyst::View::Mason::process()
defaults to render to $c->response->body,
and I didn't find an alternate way to avoid it.

please let me know if there is an alternate solution.

with this patch, Catalyst::View::Mason::render()
returns the result of the template processing,
instead of Catalyst::View::Mason::process(),
and Catalyst::View::Mason::process(),
renders the return value of Catalyst::View::Mason::render()
to $c->response->body

patch is against Rev 835

regards,
jos?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Catalyst-View-Mason.render.patch
Type: text/x-patch
Size: 1203 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20050615/9ecb2fb3/Catalyst-View-Mason.render.bin

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJun 15, '05 at 8:05p
activeJun 15, '05 at 8:05p
posts1
users1
websitecatalystframework.org
irc#catalyst

1 user in discussion

José Auguste-Etienne: 1 post

People

Translate

site design / logo © 2022 Grokbase