Re: [Templates] Accessing files from templates

[prev] [thread] [next] [Date index for 2005/01/30]

From: Bill Moseley
Subject: Re: [Templates] Accessing files from templates
Date: 16:49 on 30 Jan 2005
On Sat, Jan 29, 2005 at 10:22:35PM +0100, Johan Vromans wrote:
> Yes, it is possible to construct the 'real' current directory using
> the template source directory and the path name of the current
> template, but this is cumbersome.

I had a similar question a while back.  (My quick look showed that
Template::Provider::_load() didn't set a "path" template variable
(only name, relative to include path).

So, I stored the include path in my template vars and then looked up
the file in my Plugin.   I suspect there's an easier way to get at the
INCLUDE_PATH, but...

So, something like:

    use File::Basename;
    use File::Spec;
    my $template = $context->stash->get( 'template.name' );
    my $include  = $context->stash->get( 'my.include_path' );

    my $dir;
    for ( @$include ) {
        my $path = File::Spec->catfile( $_, $template );
        if ( -f $path ) {
            $dir = dirname( $path );
            last;
        }
    }




        -- 
        Bill Moseley
moseley@xxxx.xxx


_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

(message missing)

[Templates] Accessing files from templates
Johan Vromans 21:22 on 29 Jan 2005

Re: [Templates] Accessing files from templates
Perrin Harkins 02:56 on 30 Jan 2005

[Templates] Re: Accessing files from templates
Johan Vromans 08:46 on 30 Jan 2005

Re: [Templates] Re: Accessing files from templates
Perrin Harkins 14:13 on 30 Jan 2005

Re: [Templates] Accessing files from templates
merlyn (Randal L. Schwartz) 12:14 on 30 Jan 2005

Re: [Templates] Accessing files from templates
Vivek Khera 04:10 on 31 Jan 2005

Re: [Templates] Accessing files from templates
merlyn (Randal L. Schwartz) 20:09 on 31 Jan 2005

Re: [Templates] Accessing files from templates
Vivek Khera 20:38 on 31 Jan 2005

Re: [Templates] Accessing files from templates
merlyn (Randal L. Schwartz) 21:04 on 31 Jan 2005

Re: [Templates] Accessing files from templates
Josh Rosenbaum 20:59 on 31 Jan 2005

Re: [Templates] Accessing files from templates
merlyn (Randal L. Schwartz) 21:01 on 31 Jan 2005

Re: [Templates] Accessing files from templates
Mark Mills 23:03 on 31 Jan 2005

Re: [Templates] Accessing files from templates
Josh Rosenbaum 23:40 on 31 Jan 2005

Re: [Templates] Accessing files from templates
Bill Moseley 22:05 on 02 Feb 2005

Re: [Templates] Accessing files from templates
Bill Moseley 16:49 on 30 Jan 2005

RE: [Templates] Accessing files from templates
Jason Gottshall 18:15 on 31 Jan 2005

Re: [Templates] Accessing files from templates
merlyn (Randal L. Schwartz) 19:14 on 01 Feb 2005

Re: [Templates] Accessing files from templates
Josh Rosenbaum 21:40 on 31 Jan 2005

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52