Re: [Templates] Listing the contents of special variables
[prev]
[thread]
[next]
[Date index for 2004/09/04]
On Fri, 3 Sep 2004, Thomas, Mark - BLS CTR wrote:
> I'm trying to list the keys of the template special variable, and this kind
> of thing doesn't work:
>
> template.keys
> template.list
> var.import(template)
>
> The template special variable doesn't seem to exist as a normal hash
> variable unless one of its keys are accessed directly, i.e. template.name.
>
> Now, I can always hard code the name and modtime:
>
> [% templatevar = { name = template.name, modtime = template.modtime } %]
>
> But I'd like to be able to list the META tags as well. Is there any way to
> do it?
The template variable is a reference to Template::Document object,
so it's not a hash (and thus can't be operated on via the hash
vmethods). You can get a quick-and-dirty view of its contents like
this:
[% USE Dumper %]
[% Dumper.dump( template ) %]
If you wanted be able to iterate over it with something like the
keys vmethod, you could subclass Template::Document and add a keys
method like this:
sub keys {
# only return keys that don't begin with an underscore,
# since TT won't show you those in a template anyway
return [ grep !/^_/, keys %{ +shift } ];
}
then you _should_ (the above solution is untested) be able to do
this in your template:
[% FOREACH key IN template.keys %]
[% key %] = [% template.$key %]
[% END %]
I hope that helps (and works!).
Take care,
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!
dave@xxxxx.xxx Dig it all.
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
 |
Re: [Templates] Listing the contents of special variables
Dave Cash 13:39 on 04 Sep 2004
|