On 24/01/2008, at 3:49 AM, Nathan Waddell wrote:

One thing that I can't seem to find (and maybe I don't know where to
look) is an intermediate overview of how to use the stash in
coordination with templating systems. For example, I know that I can:

Example TT template:
<h1>A very basic template.</h1>
<p>Here's the variable you passed to this page: [% foo %]

Example catalyst snippet:
my $foo = "bar";
$c->stash->{'foo'} = $foo;

So the resulting template will print the following html:
<h1>A very basic template.</h1>
<p>Here's the variable you passed to this page: bar</p>

However, the template toolkit also allows for hashes to be passed to it, like:
my $foo = ( bar => 'Foobar');

Which can then be accessed as [% foo.bar %] - if I'm understanding it correctly.

How do you pass this hash to catalyst? By deriving a reference?

i.e.
my $foo_ref = \%foo;
$c->stash->{'foo'}= $foo_ref;

If this is so, do you have to worry about dereferencing {foo} if you
need to check its value in the stash with another Catalyst controller?

i.e.
my $foobar_ref = $c->stash->{'foo'};
my $foobar = %{$foobar_ref};

Nathan


Unless I misunderstand your question (and that's certainly not beyond the realms of possibility...), you should be able to simplify this with:
my $foo = { bar => 'Foobar', ... };
$c->stash->{foo} = $foo;

The template will correctly interpret [ % foo.bar %]

and there should be no reason another controller/action that gets forwarded to can't retrieve $c->stash->{foo}->{bar}

However, if what you're after is sending the hash back from the template to the controller (via some href action), then you can return the hash contents as named parameters: [% href = c.uri_for($something, foo), which will become a link like / something?bar=Foobar etc. If that's not what you want, I'd be inclined to put the hash into session data, since it sounds like you're trying to persist it, which is what the session is for.

Hope that's some help.

cheers
RET
_____________________________________________________
What do we want? Instant gratification! When do we want it? ...


_______________________________________________
List: Catalyst@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/

Reply via email to