GT::Template::Vars - Tied hash for template tags handling
my $vars = GT::Template->vars; print $vars->{foo};
This module is designed to provide a simple interface to GT::Template tags from
Perl code. Prior to this module, the tags()
method of GT::Template returned a
hash reference which could contain all sorts of different values - scalar
references, LVALUE references, GT::Config objects, etc. This new interface
provides a tied hash reference designed to aid in retrieving and setting values
in the same way template variables are retrieved and set from templates.
Accessing a value is simple - just access $vars->{name}
. The regular
rules of escaping apply here: if the value would have been HTML-escaped in the
template, it will be escaped when you get it.
Setting a value is easy - simply do: $vars->{name} = $value;
. ``name''
can be anything GT::Template recognises as a variable, so
$vars->{'name.key'}
would set ->{name}->{key}
(see
Advanced variables using references in the GT::Template::Tutorial manpage for more
information on complex variables).
The regular rules of escaping apply here: if escaping is turned on, a value you
set will be escaped when accessed again via $vars or in a template. If you
want to set a tag containing raw HTML, you should set a scalar reference, such
as: $vars->{name} = \$value;
.
You can use keys %$vars
to get a list of keys of the tag object, but you
should note that while $vars->{"a.b"}
is valid and
exists $vars->{"a.b"}
may return true, it will not be present in the
list of keys returned by keys %$vars
.
the GT::Template::Tutorial manpage
Jason Rhinelander
Copyright (c) 2005 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com/
Revision: $Id: Vars.pm,v 1.3 2005/03/05 01:17:20 jagerman Exp $