FAQ
hi there,
how do I access the Catalyst variable in a custom made Template
Toolkit plugin?

WhaT I have done: read up on
http://search.cpan.org/src/MRAMBERG/Catalyst-View-TT-0.27/lib/Catalyst/View/TT.pm

For example, I have my own plugin, "package
myApp::View::Template::Plugin::User"

use strict;
use warnings;
use base 'Template::Plugin';
use Template::Plugin;
use DateTime;
use DateTime::Format::Pg;

sub load {
my ( $class, $context ) = @_;
return $class;
}

sub new {
my ( $class, $context, @params ) = @_;

bless { _CONTEXT => $context, }, $class; # returns blessed
MyPlugin object
}

sub get_current_user
{
my ($class, $c) = @_;

$c->log->debug( "The type is " . ref ($c));

return $c->session->{'active_user'} ? $c->session->{'active_user'} :
$c->user->login_id;
}

===============



And in my template toolkit, "display_user.tt2" I do something like:

[% current_user = User.get_current_user(Catalyst) %]
THE current user is ([% current_user %])....


I noticed that myApp::View::Template::Plugin::User->get_current_user
doesn't print out any values.
I suspect it has not even been able to recognise the Catalyst variable.

I even tried doing "[% current_user = User.get_current_user( $Catalyst
) %]" in the display_user.tt2 template file.


Please help :)


K. akimoto

Search Discussions

  • Tomas Doran at Jun 1, 2009 at 12:03 pm

    kakimoto@tpg.com.au wrote:
    hi there,
    how do I access the Catalyst variable in a custom made Template
    Toolkit plugin?
    You don't want to do this.

    TT plugins should be for trivial formatting stuff only, teaching them
    about your application context is massively breaking abstraction.

    Cheers
    t0m

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJun 1, '09 at 11:02a
activeJun 1, '09 at 12:03p
posts2
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Tomas Doran: 1 post K. Akimoto: 1 post

People

Translate

site design / logo © 2022 Grokbase