Mathew Robertson wrote: > Hi Jonathan, > > I think the exampe of: > > @loop = ( > ... > {value_set => 2, count_distribution => 1, sum_of_counts => 36 }, > ... > ) > > is invalid, since you never generate the loop contruct like that.
"invalid" may be too strong of a word; maybe you mean "unlikely"? For brevity's sake, I was describing the contents of a variable that's about to be loaded into the template; I was not intending to address the question of how it gets put together in the first place. That said: > Usually you would do something like: > > for ($min..$max) { # - loop through to max rows > push @loop, { # \ > value_set => $_, # - make row values > count_distribution => make_value($_), # / > }; > } > $ht->param(some_loop => [EMAIL PROTECTED]); # - make rows available > $ht->param(sum_of_counts => 36); # - make max count available > > The point being that usually you build up loop content dynamicaly, say from a > database > or a computation, rather than simply outputting static content. True, but not a point that has much of an impact on my proposal. Take the example given in the documentation: my @words = qw(I Am Cool); my @numbers = qw(1 2 3); my @loop_data = (); while (@words and @numbers) { my %row_data; $row_data{WORD} = shift @words; $row_data{NUMBER} = shift @numbers; push (@loop_data, \%row_data); } $template->param(THIS_LOOP => [EMAIL PROTECTED]); -- <TMPL_LOOP NAME="THIS_LOOP"> Word: <TMPL_VAR NAME="WORD"> <br> Number: <TMPL_VAR NAME="NUMBER"> <p> </TMPL_LOOP> Everything after the "my @numbers" line and before the "$template->param" line is an example of having to jump through hoops in order to get the information into a "table format" that H::T can use. Furthermore, the related template is under some severe limitations, in that information that has not been put into @loop_data cannot be displayed from inside a <TMPL_LOOP> tag. Looking at the same example, but implementing my proposal, you'd have this: my @words = qw(I Am Cool); my @numbers = qw(1 2 3); $template->param(WORDS => [EMAIL PROTECTED]); $template->param(NUMBERS => [EMAIL PROTECTED]); -- <TMPL_LOOP> Word: <TMPL_VAR NAME="WORDS"> <br> Number: <TMPL_VAR NAME="NUMBERS"> <p> </TMPL_LOOP> Much simpler, no? > Also, I'm not confident that H::T could be extended with the > list-of-list case (without some re-work), as H::T uses > recursion for TMPL_LOOPS (eg: when a loop begins, a new > instance of H::T is created -> it becomes the current context). > Note that most of my templates use lists-of-lists to produce > tables, so I do consider this to be a must have. See, that "current context" bit is something else that I'd like to get away from with unnamed template loops. Going back to what you have in the second quote above: if I use <TMPL_LOOP NAME="some_loop">, I can only use <TMPL_VAR NAME="value_set"> and <TMPL_VAR NAME="count_distribution"> within it; I cannot use <TMPL_VAR NAME="sum_of_counts"> in there, because "sum_of_counts" isn't in the current context. Unnamed template loops wouldn't change the current context, so I'd be able to make use of any or all of the appropriate arrays or scalars within it. > The idea of unnamed template loops is a interesting idea, but > all it really does is to increase the complexity of H::T, for > no real increase in useability. I'll have to beg to differ. As things stand, the script writer has to have a strong feel for how the data that he provides is going to be used, and needs to set up the lists of hashes accordingly. The template writer is then constrained to display each list-of-hashes in a separate loop, even if he thinks that the data makes more sense bundled together in a single loop. And that's not even mentioning the "current context" constraint. With unnamed template loops, the template writer is free to bundle as much or as little of the available data into a given loop as he feels is appropriate. If that's not a real increase in useability, what is? > PS. In all of my templates, I know of exactly _zero_ cases where I could use > un-named > loop variables. Correction: Every last case you know of _could_ use unnamed loops, since unnamed loops can do everything that regular loops can. Not one of your cases _does_, obviously, since unnamed loops aren't currently implemented; but that's not the same thing. And I can think of a number of cases where unnamed loops would streamline the script writer's job without complicating the template writer's job. -- Jonathan "Dataweaver" Lang ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_idv37&alloc_id865&op=click _______________________________________________ Html-template-users mailing list Html-template-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/html-template-users