I'm trying to create a report using TT, and I'm having a little trouble
using the data structures that I already have in my program within the
template. I'm wondering if the answer to this is to reformat the data
so it is acceptable to TT, or if there is some way for me to do this
from within the template.
The data passed to the template looks like this.
$VARS = \{
'binfo' => {
'email' => '[email protected]',
'weight' => '50',
'branch' => 'The Library'
},
'items' => {
'"i18084576"' => {
'bib' => '"b13698424"',
'location' => '"nh "',
'author' => '"Brown, Marc
Tolon."',
'title' => '"Arthur\'s tooth
[CD/sound recording] / by Marc Brown."',
'call' => '"BOOK-AND-CD e BRO"'
},
'"i13882053"' => {
'bib' => '"b11926302"',
'location' => '"nh "',
'author' => '"Davis, Steve."',
'title' => '"Snowboarding /
written by Steve Davis, foreword by Bryan Iguchi."',
'call' => '"j 796.93 IGU"'
},
'"i18166076"' => {
'bib' => '"b13718733"',
'location' => '"nh "',
'author' => '"Steel,
Danielle."',
'title' => '"Amazing grace
[Large Print] / Danielle Steel."',
'call' => '"lp STE"'
}
},
'code' => 'nh'
};
I would like to output a HTML table with each row consisting of
$var1->{items}->{$item}->{call}, ...{location}, ...{author}, etc, where
$item = key of one of the Items elements. I also want them sorted by
the 'call' value.
In perl I use something like this.
foreach my $item (sort {$paging{$loc}->{$a}->{call} cmp
$paging{$loc}->{$b}->{call} || $paging{$loc}->{$a}->{author} cmp
$paging{$loc}->{$b}->{author}} keys %{$paging{$loc}}){
In my template I have been trying to use something like this, and I can
step through all the values and print what I need.
[% FOREACH item IN items %]
[% item.value.call %]
[% item.value.location %]
[% END %]
From looking at the documentation, I would have thought that using [%
item.call %] would work, but I had no luck with that.
I have tried to do some sorting of the hash using the sort virtual
method, but I don't think it can handle what I am looking to do.
[% FOREACH item IN items.sort %]
[% item %]
[% items.$item.value %]
[% items.$item.call %]
[% END %]
This should sort based on the items keys, but that doesn't seem to work
in any case. Is there any way to sort based on a sub hash value of the
elements returned. Or should I reformat my data so that the key is the
value I want to sort on?
Like
$VARS = \{
'items' => {
'"BOOK-AND-CD e BRO"-"Brown, Marc
Tolon."-"i18084576"' => {
'bib' => '"b13698424"',
'location' => '"nh "',
'author' => '"Brown, Marc
Tolon."',
'title' => '"Arthur\'s tooth
[CD/sound recording] / by Marc Brown."',
'call' => '"BOOK-AND-CD e BRO"'
},
'"j 796.93 IGU"-"Davis, Steve."-"i13882053"' => {
'bib' => '"b11926302"',
'location' => '"nh "',
'author' => '"Davis, Steve."',
'title' => '"Snowboarding /
written by Steve Davis, foreword by Bryan Iguchi."',
'call' => '"j 796.93 IGU"'
},
'"lp STE"-"Steel, Danielle."-"i18166076"' => {
'bib' => '"b13718733"',
'location' => '"nh "',
'author' => '"Steel,
Danielle."',
'title' => '"Amazing grace
[Large Print] / Danielle Steel."',
'call' => '"lp STE"'
}
},
'code' => 'nh'
};
This way as long as I can get the sort virtual method to work, it should
sort the keys based on the call and then the author.
Any suggestions would be appreciated.
Thanks
Josh
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates