Hi all
I already asked the question below some time ago but I didn't receive an
answer. I think it maybe a problem similar to the one diskussed in 'What
am I missing with using variables as hash keys in Template?' asked by James
Moore, so I post this question one more time.
I have some problems, calling perl-subroutines from within a template. I
have a module with subroutines, which are called with a hash-reference as
their only parameter. I woud like to use TT to generate a graphics-program
from a program-template and a template-file with parameters for the
program-generation. I would like to have all the parameter definitions in
the template-file and not in a special perl-skript, so I could only change
the template-file to have a different graphics-program generated. It would
be nice to define subroutine-references and hash-references in a
templatefile, but I see no easy way to do this. (The subroutines will
themselfe generate some more complex parts of the graphics-programcode.)
The only solution I found until now, is to define references to my
subroutines in the calling perl-skript and to define the parameters in the
following way:
perl-skript:
my $vars = {
� �# gr_draw_object is a routine with a hashreference as parameter
� �gr_draw_object � � => \&gr_draw_object,
};
# process input template, substituting variables
$template->process($input, $vars) || die $template->error()
template with parameterdefinitions:
[% stringdef="Teststring" %]
[%
� objectdefinition_1 = draw_object(object => "string", loctype => "view",
def => "Objekt 1")
� objectdefinition_2 = draw_object(object => "string", loctype => "view",
def => "${stringdef}")
%]
In the graphics-program-template I have things like
... graphic-commands
[% objectdefinition_1 %] ... more commands.
I see no way to define and use a hash and a hashreference with the
parameters for the subroutine in the template itself or to define a
subroutine-reference in the template. I think you could really use this
kind of definitions to be able to generate rather complex things only
driven by parameter-templates with no requirement to change some perl-code.
Any ideas, help, comments ?
Thank you
Matthias Dillier