Re: [htmltmpl] loop through a hash structure without knowing the hash keys?
Brought to you by:
samtregar
From: Mathew R. <mat...@ne...> - 2005-12-02 00:06:05
|
I agree too - what I was trying to say was that, I dont think it is even = technically possible to do it generically. Can you think of an example of how to do it generically? If you can, I=20 could quite easily modify my H::T version to support this functionality. Mat Boon Chew wrote: > > I agree with you that the coupling cannot be totally avoided, but=20 > being able to deal with template var generically in the presentation=20 > layer is very useful in avoiding having to create duplicate html code=20 > that are doing exactly the same thing.=20 > > - boon > > */Mathew Robertson <mat...@ne...>/* wrote: > > The coupling of a template to the template-params is something > that cant really be avoided - at some point the template designer > has to have some understanding of what template-variables are > being generated. Since you are the developer creating the code > that generates the template-variables, it is your responsibility > to "publish" the variable names and their meaning, it is not up to > the template designer to "figure out" what they are and what they > represent. > > That said, there is a justified argument for wanting something > like a <TMPL_DUMP some_var> which writes a dumped-block into the > target page. > > Mathew > > PS. I maintain a version of H::T which supports sub-classing so > that you can create your own TMPL tags, see: > http://members.optusnet.com.au/~mathew > > > Boon Chew wrote: > >> I want a way to quickly display all the info in a var - a Dumper >> output if you will. But more than that, like in some other >> server-side language, you can query the column lists (or hash >> keys) and loop through those and use a piece of generic code when >> all you intend to do is to display everything in the var. >> >> Imagine yourself wanting to output all the info in a reference to >> an array of hashes (which essentially mimics a database table), >> the HTML code can really be made the same if a construct is >> available to loop through things. >> >> The tight coupling of knowledge between what's being sent from >> the perl code and the HTML can be avoided, that's the whole point >> of the design of the template module (vs Mason where you mingle >> Perl code with display code) right? It just seems ugly when I >> have to tell a designer to go look at the perl file to see what >> he is getting in the var. He should be able to find that out >> from some sensible constructs. >> >> - boon >> >> */Mathew Robertson <mat...@ne...>/* wrote: >> >> It sounds like you need a tool which simply dumps the >> template variable names (ie: using the $ht->params() >> function), rather than some special mode to H::T >> >> Mathew >> >> Boon Chew wrote: >> >>> Ya sorry, that's what I meant. >>> >>> Right now I am working on some site code, and the designer >>> sometimes have to come to me for stuff because he doesn't >>> always know what hash keys I am passing to him (say >>> sometimes I might add a new one, sometimes he mistype one, >>> etc.). The whole point of doing this template separation is >>> to decouple things, but if the designer can only figure out >>> what's being passed into the template by looking at the >>> module code, it kinda defeats the whole purpose. >>> >>> It would be such great convenience to be able to dump the >>> whole thing on the HTML with a call like this: >>> >>> <tmpl_var story_loop> >>> >>> or >>> >>> <tmpl_loop story_loop> >>> <column_var> <-- outputs all keys here >>> </tmpl_loop> >>> >>> */Carl Franks <fir...@gm...>/* wrote: >>> >>> > e.g. >>> > >>> > >>> > >>> >>> a TMPL_LOOP doesn't take a hash, it takes an array-ref >>> of hash-refs >>> that would be >>> >>> my @loop =3D ( >>> {name =3D> 'a'}, >>> {name =3D> 'b'}, >>> ); >>> >>> $tmpl->param( students =3D> \@loop ); >>> >>> If you knew that already, give an example of what sort >>> of data you >>> want to put in, and what you want the HTML to look like. >>> >>> Cheers, >>> Carl >>> >>> >>> ------------------------------------------------------- >>> 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_id=16865&op=3Dclick >>> _______________________________________________ >>> Html-template-users mailing list >>> Htm...@li... >>> https://lists.sourceforge.net/lists/listinfo/html-templat= e-users >>> >>> >>> -------------------------------------------------------------= ----------- >>> *Yahoo! Personals* >>> Single? There's someone we'd like you to meet. >>> Lots of someones, actually. Yahoo! Personals >>> <http://us.rd.yahoo.com/evt=3D36108/*http://personals.yahoo.c= om%20> >> >> >> >> ------------------------------------------------------------------= ------ >> Yahoo! DSL >> <http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=3D37474/*http://p= romo.yahoo.com/broadband/%20> >> Something to write home about. Just $16.99/mo. or less=20 > > > -----------------------------------------------------------------------= - > Yahoo! DSL=20 > <http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=3D37474/*http://promo.= yahoo.com/broadband/%20>=20 > Something to write home about. Just $16.99/mo. or less=20 |