FAQ
Hi,

I am trying to use a custom TT filter in a Catalyst app.

In MyApp.pm I use:

'View::TT' => {
PLUGIN_BASE => __PACKAGE__->path_to('lib'),
},

In the lib dir I have a Diverse/NoDia.pm module that looks like this:

package Diverse::NoDia;

use Template::Plugin::Filter;
use base 'Template::Plugin::Filter';

sub filter {
my ($self, $text) = @_;
$text =~ tr/??????????/astiaASTIA/;
return $text;
}
1;

In the template I use:

[% USE NoDia = Diverse.NoDia -%]
[% FILTER $NoDia -%]
...
[% END %]

But it gives the following error:

Couldn't render template "plugin error - Can't locate object method "load"
via package "D:\web\TranzactiiBursiere\lib::Diverse::NoDia" (perhaps you
forgot
to load "D:\web\TranzactiiBursiere\lib::Diverse::NoDia"?) at
D:/usr/site/lib/Template/Plugins.pm line 215.
"

How can I define a custom TT filter in a Catalyst app?

(I need to filter a text depending on a condition, and I don't know if I can
use another method for doing this.)

Thank you.


Octavian

Search Discussions

  • Chisel Wright at May 22, 2007 at 11:43 am

    On Tue, May 22, 2007 at 01:20:46PM +0300, Octavian Rasnita wrote:
    Hi,

    I am trying to use a custom TT filter in a Catalyst app.

    In MyApp.pm I use:

    'View::TT' => {
    PLUGIN_BASE => __PACKAGE__->path_to('lib'),
    },
    Not strictly a Catalyst question, but my guess is you're using
    PLUGIN_BASE incorrectly.

    According to 'perldoc Template::Plugin' (which of course you've already
    read):


    Use the PLUGIN_BASE option to specify the namespace that you use. e.g.

    use Template;
    my $template = Template->new({
    PLUGIN_BASE => ?MyOrg::Template::Plugin?,
    });

    You're not specifying a namespace, you're giving a path ...
    --
    Chisel Wright
    e: chisel@herlpacker.co.uk
    w: http://www.herlpacker.co.uk/

    My computer's so fast it finishes an infinite loop in 5 minutes.
  • Adeola Awoyemi at May 22, 2007 at 12:00 pm
    Hello,

    In your TT::View you could add:

    use base 'Catalyst::View::TT';

    sub noDia {
    my $text = shift;
    $text =~ tr/??????????/astiaASTIA/;
    return $text;
    }

    __PACKAGE__->config({
    FILTERS => {
    'noDia' => \&noDia,
    },
    });

    So, in your template you should be able to use:

    [% FILTER noDia -%]
    data to parse
    [% END %]


    I hope this helps. This is just form my knowledge of TT. I'm still
    getting used to Catalyst so someone else might have a better idea but
    its worth a try ;)

    Adeola

    On 22 May 2007, at 11:20, Octavian Rasnita wrote:

    Hi,

    I am trying to use a custom TT filter in a Catalyst app.

    In MyApp.pm I use:

    'View::TT' => {
    PLUGIN_BASE => __PACKAGE__->path_to('lib'),
    },

    In the lib dir I have a Diverse/NoDia.pm module that looks like this:

    package Diverse::NoDia;

    use Template::Plugin::Filter;
    use base 'Template::Plugin::Filter';

    sub filter {
    my ($self, $text) = @_;
    $text =~ tr/??????????/astiaASTIA/;
    return $text;
    }
    1;

    In the template I use:

    [% USE NoDia = Diverse.NoDia -%]
    [% FILTER $NoDia -%]
    ...
    [% END %]

    But it gives the following error:

    Couldn't render template "plugin error - Can't locate object method
    "load" via package "D:\web\TranzactiiBursiere
    \lib::Diverse::NoDia" (perhaps you forgot
    to load "D:\web\TranzactiiBursiere\lib::Diverse::NoDia"?) at D:/usr/
    site/lib/Template/Plugins.pm line 215.
    "

    How can I define a custom TT filter in a Catalyst app?

    (I need to filter a text depending on a condition, and I don't know
    if I can use another method for doing this.)

    Thank you.


    Octavian


    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/
    catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    --
    Creative Developer - Digital Craftsmen Ltd
    Exmouth House, 3 Pine Street
    London, EC1R 0JH
    t: +44 20 7183 1410
    f: +44 20 7099 5140
    m: +44 79 3952 0786
    w: http://www.digitalcraftsmen.net/
  • Aristotle Pagaltzis at May 22, 2007 at 2:37 pm
    Hi Octavian,

    * Octavian Rasnita [2007-05-22 12:30]:
    I am trying to use a custom TT filter in a Catalyst app.
    my answer has nothing to do with that ? but:
    sub filter {
    my ($self, $text) = @_;
    $text =~ tr/??????????/astiaASTIA/;
    return $text;
    }
    Have you seen Text::Unidecode?

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMay 22, '07 at 11:20a
activeMay 22, '07 at 2:37p
posts4
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase