List Info

Thread: Using a custom TT filter




Using a custom TT filter
country flaguser name
Romania
2007-05-22 05:20:46
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:webTranzactiiBursierelib:iverse::
NoDia" (perhaps you 
forgot
to load "D:webTranzactiiBursierelib:iverse::
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: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

Re: Using a custom TT filter
country flaguser name
United Kingdom
2007-05-22 05:43:37
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: chiselherlpacker.co.uk
w: http://www.herlpacker.co
.uk/

  My computer's so fast it finishes an infinite loop in 5
minutes.

_______________________________________________
List: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

Re: Using a custom TT filter
country flaguser name
United Kingdom
2007-05-22 06:00:55
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:webTranzactiiBursiere 
> lib:iverse::
NoDia" (perhaps you forgot
> to load "D:webTranzactiiBursierelib:iverse::
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: Catalystlists.rawmode.org
> Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.
com/ 
> catalystlists.rawmode.org/
> Dev site: http://dev.catalyst.per
l.org/

--
Creative Developer - Digital Craftsmen Ltd
Exmouth House, 3 Pine Street
bond, EC1R 0JH
t: +44 20 7183 1410
f: +44 20 7099 5140
m: +44 79 3952 0786
w: http://www.digitalcr
aftsmen.net/





_______________________________________________
List: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

Re: Using a custom TT filter
country flaguser name
Germany
2007-05-22 08:37:38
Hi Octavian,

* Octavian Rasnita <orasnitagmail.com> [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/&g
t;

_______________________________________________
List: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )