Accessible Instance methods
Template($root = ".", $unknowns = "remove")
Constructor. May be called with two optional parameters. The
first parameter sets the template directory (see
set_root(), the second parameter sets the policy
regarding handling of unknown variables.
The function checks that $root is a valid directory and sets
this directory as the base directory where templates are being
stored.
set_unknowns($unknowns = "remove")
The function sets the policy for dealing with unresolved
variable names. Must be either "remove", "comment" or "keep". If
set to "keep", those are left untouched. If set to "comment",
unresolved variable names are transformed into HTML comments
reporting the error. If set to "remove", unresolved variable
names are silently removed (the default).
set_file($varname, $filename = "")
The function defines a filename for the initial value of a
variable. It may be called with either a $varname/$filename pair
or with a hash of $varname/$filename pairs. The files are not
loaded until they are needed.
set_block($parent, $varname, $name = "")
A variable $parent may contain a variable block named by
$varname. The function removes that block from $parent and
replaces it with a variable reference named $name. If $name is
omitted, it is assumed to be the same as $varname.
set_var($varname, $value = "")
The functions sets the inital value of a variable. It may be
called with either a $varname/$value pair or with a hash of
$varname/$value pairs.
The function returns the value of the variable named $varname,
with all defined variable values filled in. The resulting string
is not "finished", that is, the unresolved variable name policy
has not been applied yet.
This is a shorthand for print $this->subst($varname).
parse($target, $varname, $append = false)
The function substitutes the values of all defined variables in
the variable named $varname and stores or appends the result in
the variable named $target.
If $varname is an array of variable names, $append is ignored.
The variables named by $varname are being sequentially
substituted and the result of each substitution step is stored
in $target. The resulting substitution is available in the
variable named by $target, as is each intermediate step for the
next $varname in sequence.
pparse($target, $varname, $append = false)
A shorthand for print $this->parse(...).
Returns a hash of all defined values, keyed by their names.
Returns the value of the variable named by $varname. If $varname
references a file and that file has not been loaded, yet, the
variable will be reported as empty.
When called with an array of variable names, an hash of values,
keyed by their names, will be returned.
The function will return a hash of unresolved variable names in
$varname, keyed by their names (that is, the hash has the form
$a[$name] = $name).
The function will returned the finished version of $str, that
is, the policy regarding unresolved variable names will be
applied to $str.
The function will print the finished version of the value of the
variable named by $varname.
The function will return the finished version of the value of
the variable named by $varname.
This function can be overridden by your subclass of Template. It
will be called with an error message to print.
Internal instance methods
When called with a relative pathname, this function will return
the pathname with the appropriate directory from $this->root
prepended. Absolute pathnames are taken unchanged.
The resulting filename must exist or an error is generated.
The function will construct a variable name regexp for a given
variable name.
If a variable is undefined or empty and is backed by a filename,
the backing file will be loaded and the files contents will be
assigned as the variables value.
This function is called whenever an error occurs and will handle
the error according to the policy defined in
$this->halt_on_error.