[Catalyst] Using a post argument in a template

Tomas Doran bobtfish at bobtfish.net
Fri Jul 25 14:15:30 BST 2008


On 25 Jul 2008, at 13:40, James S. White wrote:

> I was trying to munge the paramaters in the controller, I just  
> can't figure
> out how to access the variables of a controller method in the  
> template. I'd
> be more than happy to pass the argument to a controller, and then  
> have the
> view fetch it from the controller, and then the template read it  
> from the view,
> If I had any idea how to dereference the variables in order to set  
> them in
> new components. I was just trying to keep it walk before running  
> and I keep
> tripping over my feet.
>

You want to put the data into the 'stash'.

So in your controller you have:
my ( $self, $c, $arg ) = @_;
$arg =~ s/stuff/munge/;
$c->stash->{somearg} = $arg;

And in your view, you say: [% c.stash.somearg %]

You don't really want the view to be able to see the controller's  
internal state / mechanics, and so you have to explicitly stash any  
data which you want to be able to see from the view.

HTH
t0m




More information about the Catalyst mailing list