Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Finding the dirpath of a template (Template::Toolkit)

by alien_life_form (Pilgrim)
on Jan 23, 2004 at 12:46 UTC ( [id://323538]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings,

I need to find the absolute path of the directory containing the file curently being processed (by Template::Toolkit) if at all possible from within the template.

I tried the File and Dir plugins, to no avail. (USE File('.'); File.cwd() gives the cwd of the script, NOT the template).

Ideas anybody? What am I missing?

Cheers,
alf
You can't have everything: where would you put it?
  • Comment on Finding the dirpath of a template (Template::Toolkit)

Replies are listed 'Best First'.
•Re: Finding the dirpath of a template (Template::Toolkit)
by merlyn (Sage) on Jan 23, 2004 at 12:55 UTC
Re: Finding the dirpath of a template (Template::Toolkit)
by alien_life_form (Pilgrim) on Jan 23, 2004 at 17:26 UTC
    Greetings,

    I did some more research and it looks the problem is thornier then I thought.

    A code similar to this (which is also discussed in Dynamically altering static TT templates - by Ovid) would appear to cut it, but I am loathe to use such hackery - chiefly inside an Apache::registry script.

    component.name does not cut it, by the way.In the end, every path that I'v been able to squeeze out of the template, filters and plugins refers to the script dir (not the template), or it's relative to the template dir

    And yet the task I need to do looks mundane enough that somebody would have needed it... (the task, put briefly, is - get a list of template filenames, find the best match with a given dynamic rule, include the selected template)

    I will heed merlyn's advice and go to the TT2 list, but it looks pretty hopeless so far.


    Cheers,
    alf
    You can't have everything: where would you put it?
Re: Finding the dirpath of a template (Template::Toolkit)
by mcogan1966 (Monk) on Jan 23, 2004 at 13:15 UTC
    You might want to consider hacking into the source code of Template::Toolkit and adding a function that will give you the location of the file it is processing. Don't know if that will work, and I would strongly recommend backing up the source code first.

    Never be afraid to add functionality to existing code.

      "hack the source"? Surely you jest. Template Toolkit is so incredibly hook-able and extensible. It even has toolkit in the name! At worst, you'd need to subclass the Template::Document class and provide an extra document variable. At worst.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://323538]
Approved by xenchu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found