[Catalyst] Jemplate View and Catalyst Object
Jonathan Rockway
jon at jrock.us
Thu Jul 19 01:47:01 GMT 2007
On Wednesday 18 July 2007 02:39:22 pm Patrick McDonnell wrote:
> TTSite view doesn't seem to exist under the Jemplate views. For instance,
> in a TTSite template, I can do something like [%
> Catalyst.uri_for('myAction') %], but I cannot do that under the Jemplate
> templates.
Right. [% ... %]s are expanded on the *client side* by the browser. Of
course they can't call methods on the Catalyst object.
Here's a solution. In a controller where your AJAXy actions live, do
something like:
package MyApp::Controller::AJAXy::Stuff;
....
sub begin :Private {
$c->stash->{action} = { foo => $c->uri_for('/foo'), ... };
}
# your actions go here
sub foo :Local { ... }
....
sub end :Private {
# convert stash to JSON or whatever
}
Basically you just send some extra metadata (about actions) back with each
response. Then in your jemplate you can say:
<a href="[% action.foo %]/some/arguments">whatever</a>
Keep in mind that TT's "uri" filter is available for escaping some/arguments
if necessary.
Anyway, this is not ideal... but it is easy to do.
For extra credit create an RPC interface and integrate it with Jemplate and
Catalyst :) The Asynapse talk at YAPC::Asia inspired me to think about doing
something like that, but I haven't gotten to it yet. Implementations
welcome.
Regards,
Jonathan Rockway
--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part.
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070718/9d0bc7a9/attachment.pgp
More information about the Catalyst
mailing list