[htmltmpl] How to manipulate rows in returned resultset
Brought to you by:
samtregar
From: Kapoor, N. <nis...@xc...> - 2006-03-13 22:41:34
|
For populating loops, I get the resultset from db, and assign it = directly to the loop_var. This works wonderfully for most cases, except = where there is a need to process each row before assigning it to the = template. One particular case is where I am retrieving a resultset after = a search query, and I need to highlight the text that was searched for. Is there a way I can continue to use the 'single' assignment, and still = achieve this objective? Thanks, Nishi Here is some code snippet to explain it more: my $data =3D &getDataFromDB; $template->param(myLoopVar =3D> $data); #preferred way #BUT, if I need to bold the 'search text', I need to iterate through the = loop my @loopData=3D(); foreach my $rec (@{$data}) { my %loopRow; $rec->{title} =3D~ s/(\b$searchText\b)/<b>$1<\/b>/ig; $loopRow{title} =3D $rec->{title}; push @loopData, \%loopRow; } $template->param(myLoopVar =3D> \@loopData); |