[Petal] Implementation question
William McKee
william@knowmad.com
Wed, 21 Aug 2002 11:40:37 -0400
Hi folks,
Looking for some advice. I'm building a template that will display a list
of names and phone numbers in a series of rows. If the users selects one
of the rows (identified by an id), I want to make that row appear in a
form so that the user can update the information. So, I need to have a way
to check whether the current row show be put into a form or displayed
normally.
My initial thoughts are to check whether the id given to the script is the
same as the id of the current row. However, Petal doesn't support this
kind of evaluation (yet?). My next thought was to add a new element to my
list which could be evaluated true/false. Ok, that sounds good. How can I
do it?
Option A:
In my Perl script, loop over each element, test whether its id equals the
id passed to the script and set a value.
Option B:
Write an anonymous subroutine that compares the value of the id passed to
the script with the id of the current row (as passed to the subroutine by
the template). Will this become a closure (is that the right term)? Will
the values get updated as I continue to use the script (I ask because I
know that Petal is caching these templates)? I have not tested this idea.
So my question for you, if you're still with me, is what's the most
efficient way to do this? Option A or Option B?
Thanks,
William
PS: Here's what the template would theoretically look like if I used
Option A (I ran into the bug I submitted when trying to actually use this
format):
<?petal:repeat="rater raters"?>
<tr petal:if="false: rater.edit">
<td petal:content="rater.first_name">First Name</td>
<td petal:content="rater.last_name">Last Name</td>
<td petal:content="rater.relation">Relation</td>
<td petal:content="rater.phone">Phone</td>
<td petal:content="rater.email">Email</td>
</tr>
<tr petal:if="true: rater.edit">
<td><input petal:attr="name string:first_name" petal:attr="value
rater.first_name" type="string" size="15" /></td>
<td><input petal:attr="name string:last_name" petal:attr="value
rater.last_name" type="string" size="15" /></td>
<td><input petal:attr="name string:relation" petal:attr="value
rater.relation" type="string" size="18" /></td>
<td><input petal:attr="name string:phone" petal:attr="value rater.phone"
type="string" size="11" /></td>
<td><input petal:attr="name string:email" petal:attr="value rater.email"
type="string" size="35" /></td>
</tr>
<?end?>
--
Lead Developer
Knowmad Services Inc. || Internet Applications & Database Integration
http://www.knowmad.com