Ovid has asked for the wisdom of the Perl Monks concerning the following question:

I'm sure this is answered somewhere in the docs, but I can't find it (I'm curious why Google returns no matches when doing a site: search on http://template-toolkit.org).

When I use a Template Toolkit plugin -- [% USE my_plugin %] -- how can a plugin determine its own name? I am building stuff that uses plugins in some strange ways and it would be helpful if a plug can "self-identify". I started out by doing something like the following:

[% USE my_plugin "some_identifier" %]

However, having to pass that identifier every time means a chance for a typo every time. Further, if a plugin presents a form and later handles the form data (these are Web-based apps I'm working with), I need it to be able to send the user to another page with the same plugin handling the data. Passing the ID in the template means I have to synchronize the ID across templates: not good. Hard-coding the ID into every plugin means one more thing that programmers have to remember, so that's also not a good alternative.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Runtime determination of TT plugin name
by belkajm (Beadle) on Aug 08, 2002 at 21:08 UTC

    From a brief look at the TT docs, it appears that the plugins are object oriented, and take their name from the package they are in, so couldn't you use that fact to get the plugin name?

    Sorry if this is completely wide of the mark, but i haven't been using perl since june of last year and am only just about to get back into it.

    Hope this helped,
    Yoda

    p.s. i like the prolog code you are working on. managed to figure out how it worked even with my absence from perl.

      Um, um, uhhh... well, um, let's see.

      Here's a piece of free advice: never post to Perlmonks while hung over. I feel really stupid right now. Naturally, the first argument to the constructor is the class name. Sigh.

      As for the Prolog code, I've had to put it down for a bit while I caught up on my social life. I hope to return to it next week, but no promises :)

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.