Re: How to manipulate rows in returned resultset

Roger Burton West <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
On Mon, Mar 13, 2006 at 04:41:15PM -0600, Kapoor, Nishikant wrote:
>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?

Well, you could cheat and roll the loop into a map statement...

my $data = &getDataFromDB;
map {$data[$_]{bold}=1} 0..$#{$data};
$template->param(myLoopVar => $data);

and have a

<tmpl_if name=bold><b></tmpl_if>
<tmpl_var name=title escape=html>
<tmpl_if name=bold></b></tmpl_if>

You really shouldn't be putting html markup into template parameters
anyway, without a very good reason.

Roger


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.