Re: [htmltmpl] Re: Patches for HTML-Template-2.5.tar.gz
Brought to you by:
samtregar
From: simran <sim...@le...> - 2002-07-24 23:40:25
|
On Thu, 2002-07-25 at 05:20, Sam Tregar wrote: > On Wed, 24 Jul 2002, Yunliang Yu wrote: > > > 4. TMPL_VAR can now have a default value > > > > <TMPL_VAR NAME="PARAMETER_NAME" VALUE="default value"> > > Some people will like this, I imagine. Maybe call it "DEFAULT"? I think > I might take this as a separate patch. What do others think? This one sounds like a brilliant idea. Its looks like a short form for: <tmpl_unless name="param_name">my_default</tmpl_unless> changes to: <tmpl_var name="param_name" value="my_default"> It would certainly make some templates a lot cleaner. > > 6. add __count__ to loops > > > > <TMPL_VAR NAME="__count__">-th record in the loop. > > Well, this something people are perpetually asking for, so I suppose I > should add it at some point. It's just so easy to do when you need it > that I never considered it a priority. Can you send me this one as a > separate patch too? > woohooo :-) Here is a patch i submitted a whlie ago that does nothing but a '__counter__' variable if loop_context_vars is set. *** Template.pm.orig Thu Apr 18 09:25:07 2002 --- Template.pm Thu Apr 18 09:30:56 2002 *************** *** 617,629 **** default) four loop context variables are made available inside a loop: __FIRST__, __LAST__, __INNER__, __ODD__. They can be used with <TMPL_IF>, <TMPL_UNLESS> and <TMPL_ELSE> to control how a loop is ! output. Example: <TMPL_LOOP NAME="FOO"> <TMPL_IF NAME="__FIRST__"> This only outputs on the first pass. </TMPL_IF> <TMPL_IF NAME="__ODD__"> This outputs every other pass, on the odd passes. </TMPL_IF> --- 617,636 ---- default) four loop context variables are made available inside a loop: __FIRST__, __LAST__, __INNER__, __ODD__. They can be used with <TMPL_IF>, <TMPL_UNLESS> and <TMPL_ELSE> to control how a loop is ! output. ! ! In addition to the above, a __COUNTER__ VAR is also made available ! when loop context variables are turned on. ! ! Examples: <TMPL_LOOP NAME="FOO"> <TMPL_IF NAME="__FIRST__"> This only outputs on the first pass. </TMPL_IF> + <TMPL_VAR NAME="__COUNTER__"> + <TMPL_IF NAME="__ODD__"> This outputs every other pass, on the odd passes. </TMPL_IF> *************** *** 1860,1869 **** # die_on_bad_params set output() will might cause errors # when it tries to set them. if ($options->{loop_context_vars}) { ! $pmap{__first__} = HTML::Template::VAR->new(); ! $pmap{__inner__} = HTML::Template::VAR->new(); ! $pmap{__last__} = HTML::Template::VAR->new(); ! $pmap{__odd__} = HTML::Template::VAR->new(); } } elsif ($which eq '/TMPL_LOOP') { --- 1867,1877 ---- # die_on_bad_params set output() will might cause errors # when it tries to set them. if ($options->{loop_context_vars}) { ! $pmap{__first__} = HTML::Template::VAR->new(); ! $pmap{__inner__} = HTML::Template::VAR->new(); ! $pmap{__last__} = HTML::Template::VAR->new(); ! $pmap{__odd__} = HTML::Template::VAR->new(); ! $pmap{__counter__} = HTML::Template::VAR->new(); } } elsif ($which eq '/TMPL_LOOP') { *************** *** 2731,2741 **** @{$value_set}{qw(__first__ __inner__ __last__)} = (0,1,0); } $odd = $value_set->{__odd__} = not $odd; } $template->param($value_set); $result .= $template->output; $template->clear_params; ! @{$value_set}{qw(__first__ __last__ __inner__ __odd__)} = (0,0,0,0) if ($loop_context_vars); $count++; } --- 2739,2750 ---- @{$value_set}{qw(__first__ __inner__ __last__)} = (0,1,0); } $odd = $value_set->{__odd__} = not $odd; + $value_set->{__counter__} = $count + 1; } $template->param($value_set); $result .= $template->output; $template->clear_params; ! @{$value_set}{qw(__first__ __last__ __inner__ __odd__ __counter__)} = (0,0,0,0,0) if ($loop_context_vars); $count++; } |