> Man. All of this contorting of TMPL_LOOPs has made me happy I use
> CGI.pm to create most of my forms. . .
>
> $popup=$q->pop_up(-class=>'prettyHTMLClass',-name=>'foo',-values=>
> [1..10],-default=>5);
>
> Then if my designer wants more control, I just stuff that into a
> TMPL_VAR named POPUP. If not, I just make the whole form and stuff
> that into a TMPL_VAR.
What if your designer wants to use a set of radio buttons? Then you have to
recode.
> Under what circumstances is it not good to use my example above?
I personally think it breaks the seperation between presentation and
implementation. I wouldn't do it.
> Can a designer actually suss out a rats nest of TMPL_LOOPS and
> conditionals anyway?
Our designers had no problem with it... seriously H::T isn't very complex.
That's it's whole point. It's a simple, yet powerful, solution.
I sent one of the subscribers here the function I normally use to solve this
"problem" in my own code and he suggested that I sent it out to everyone, so
here ya go:
#-----------------------------------------------------------------
# Purpose: Creates a Template friendly Array for select/radio/etc.
#
# Params:
# the value of the selected item
# an array ref of the items to display to the user
# (optional) an array ref of the values hidden behind
# each of the items
#-----------------------------------------------------------------
sub GetLoopList
{
my ( $selected_item ) = shift @_ ;
my ( $list_ref ) = shift @_ ;
my ( $values_ref ) = shift @_ || undef() ;
my ( $i , @item_list ) ;
if ( ! defined ( $values_ref ) ) {
$values_ref = $list_ref ;
}
for( $i=0 ; $i<scalar(@{$list_ref}); $i++ ) {
push ( @item_list , { 'item' => $list_ref->[$i] ,
'value' => $values_ref->[$i] } ) ;
if ( $selected_item eq $list_ref->[$i] ) {
@item_list[-1]->{'is_selected'} = 1 ;
}
}
return ( \@item_list ) ;
}
So your code can look like:
@months = qw( January February March April May June July August
September October November December ) ;
$tokens->{'months'} = GetLoopList( 3 , \@months , [1..12] ) ;
$template->param( $tokens ) ;
And your template could look like:
<select name="month">
<TMPL_LOOP NAME=MONTHS>
<option value="<TMPL_VAR ESCAPE=HTML NAME=VALUE>"<TMPL_IF
NAME=IS_SELECTED> selected</TMPL_IF>><TMPL_VAR NAME=ITEM>
</TMPL_LOOP>
</select>
And the result would look like:
<select name="month">
<option value="1">January
<option value="2">February
<option value="3" selected>March
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">August
<option value="9">September
<option value="10">October
<option value="11">November
<option value="12">December
</select>
Or the designer could change the template to:
<TMPL_LOOP NAME=MONTHS>
<input type="radio" name="month" value="<TMPL_VAR ESCAPE=HTML
NAME=VALUE>"<TMPL_IF NAME=IS_SELECTED> checked</TMPL_IF>> <TMPL_VAR
NAME=ITEM>
</TMPL_LOOP>
And the result would be:
<input type="radio" name="month" value="1"> January
<input type="radio" name="month" value="2"> February
<input type="radio" name="month" value="3" checked> March
<input type="radio" name="month" value="4"> April
<input type="radio" name="month" value="5"> May
<input type="radio" name="month" value="6"> June
<input type="radio" name="month" value="7"> July
<input type="radio" name="month" value="8"> August
<input type="radio" name="month" value="9"> Sepetember
<input type="radio" name="month" value="10"> October
<input type="radio" name="month" value="11"> November
<input type="radio" name="month" value="12"> December
Kenny
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]