> > So I tried to put
> > $context->process( sub { 'my text' } ); into 'new' method of
my
> > plugin. But it does not work - no output is produced.
> 
> The context will have processed the template and returned the
output
> text ('my text') to the caller.  But unless the plugin does
something
> with it, this text will just disappear.  TT doesn't
automatically pipe
> all output back to the user.

Shame on me! Sure it returns output to the caller. I was a bit
tired last night, so I missed the obvious thing.

> > So I'm asking for TT guru's advice - is this trick possible
> > anyway?
> 
> No.  The new() method is for creating plugin objects (or other
values)
> which get assigned to variables.  You can return some text from
a 
> plugin new() method, but then you have to explicitly print (i.e.
GET)
> the value in the template.
> 
>   [% USE SomeText %]       # sub new { return 'some text' }
>   [% SomeText %]           # some text

Thanks, I have done it already (returning coderef instead of
text).

Actually, I tried to create a very simple and easy to use data
dumper. I am a bit tired of writing
[% USE Dumper; '<pre>'; Dumper.dump( foo, bar ); '</pre>' %]
- so I created plugin, which performs same operation with less
keystrokes. No I use it this way:
[% USE DD; DD( foo, bar ) %]
- and this is a bit easier.


By the way, it will (possibly) be a good idea to have the ability
to create system-wide autoloading plugin. For example, if one
could just put my DD.pm into some dir - and write simply [% DD(
foo ) %], getting rid of USE DD directives. It might be a kind of
extending TT syntax. I understand that I can preload module whed
creating Template object - but I am working with dozens of
independent scripts, which are using TT, and it is not always
possible to modify them.


-- 
С уважением, Сергей Мартынов.


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to