On Fri, 16 Apr 2004 [EMAIL PROTECTED] wrote:

> Having finished the HMTL-slides presentation system I mentioned in my
> previous message I am now ready to take the big plunge to redo my site
> in TT.
>
> One of the things I'd like to do is this. If a document contains a META
> variable 'date_first_pub' the check the validity of the date (which must
> be in ISO8601 format) and if it is valid convert it to epoch so it can
> be fed to the Date plugin. My first feeling was to enable EVAL_PERL and
> add some perl code, but after some reconsideration I'd prefer to do this
> with a custom made plugin. I found some pointers in the Badger on how to
> write your own plugins, but what escapes me is where do I put it? I'd
> rather not put in in the standard perl library tree as I feel it would
> be better to store it under the project directory where everything else
> is stored.
>
> Any pointers giving me a nudge in the right direction would be
> appreciated.

There are basically just two things you'll need to worry about:

 1) The script that processes your template (or the startup.pl
    script, if you're using mod_perl) will have to have a
    'use lib' line pointing to the place where you want to store
    your custom plugins.

 2) The Template object will have to be configured to know about
    your plugins' namespace, via the PLUGIN_BASE configuration
    option.

So, let's say you have a script called /home/me/myscripts/render.pl
and you have a plugin CoolPlugins::ValidDate that lives at
/home/me/myplugins/CoolPlugins/ValidDate.pm .  In your template
(which is process()'ed by render.pl in this example), you want to be
able to use your plugin as follows:

  [% USE ValidDate %]
  [% IF ValidDate.check(date_first_pub) %]
  date_first_pub is a valid ISO8601 date
  [% ELSE %]
  where'd you dig up that funky date format?
  [% END %]

In /home/my/myscripts/render.pl:

  #!/usr/bin/perl

  use strict;
  use lib qw(/home/me/myplugins);

  use Template;

  my $tt = new Template( { PLUGIN_BASE => 'CoolPlugins' } );

  ... etc.

The key pieces are the 'use lib' line and the PLUGIN_BASE config
option in the Template instantiation.  The former helps Perl (and by
extension, TT) find your module and the latter lets you USE it in
your template without the having to call it CoolPlugins.ValidDate.

Hope that helps.

Dave

/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash                              Power to the People!
Frolicking in Fields of Garlic               Right On-Line!
[EMAIL PROTECTED]                                  Dig it all.

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

Reply via email to