Hello list,
I am all new to TT2 and searching the monthly gzip'ed archives is a
pain, so I decided to create a simple test case for the demonstartion of
my problem and ask this list. I read a lot of documentation so far, so
please be patient, if my question still seems stupid and/or simple to
you.
I try to process data from a hash ref in a filter, but it seems to be
"stringified" until it reaches the filter, at least that is how I
interpret the output you can see below.
Basically, instead of the line
HASH(0x84be56c)
I would like to create something like
service_name: src1 dst1 serv1
in the filter.
For that, I would need to have the data as seen from the Dumper(
$one->services ) output available in the filter subroutine. How can I
achieve that?
Thank you for any pointers of what I am doing wrong or of better ways to
achieve what I am trying to do ...
Daniel.
########### OUTPUT ##############
#Dumper:
$VAR1 = {
'service_name' => {
'src' => 'src1',
'srv' => 'serv1',
'dst' => 'dst1'
}
};
# Filter:
GOT: $VAR1 = 'HASH(0x84be56c)';
#Template:
Participant: 1
HASH(0x84be56c)
########### TEMPLATE ##############
[% FOREACH participant IN participants %]
Participant: [% participant.primary_key %]
[% FOREACH service IN participant.services %]
[% service FILTER flt_my %]
[% END %]
[% END %]
########### CODE ##############
# Participant is a class of my own that has an accessor called
# "services" that gets/sets a hash-ref (see Dumper-output).
# "primary_key is another accessor that gets/sets a scalar value for the
PK.
use Template;
use Template::Filters;
use Participant;
use Data::Dumper;
sub my_filter {
my $arg = shift;
print "GOT: ", Dumper( $arg );
return $arg;
}
# Create Template-Filter-Object with filters that we will need.
my $filters = Template::Filters->new( {
FILTERS => {
flt_my => \&my_filter,
}
});
# Create Participant with primary_key "1".
my $one = Participant->new( [ 1 ] );
$one->services( {
service_name => {
src => 'src1',
dst => 'dst1',
srv => 'serv1',
}
} );
my @participants = ( $one );
print Dumper( $one->services );
# Create template object.
my $template = Template->new( LOAD_FILTERS => $filters )
or die Template->error();
# Process template (output written to STDOUT).
$template->process( 'test.tt2',
{
participants => @participants,
}
)
or die "ERROR:" . $template->error();
########### END CODE #############
Best regards,
Daniel Brunkhorst.
________________________________
Dataport
Altenholzer Str 10 - 14, 24161 Altenholz
Internet:www.dataport.de
E-Mail: [EMAIL PROTECTED]
Telefon: 0431 - 32 95 6318
Telefax: 0431 - 32 95 410
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates