Re: [htmltmpl] loop through a hash structure without knowing the hash keys?
Brought to you by:
samtregar
From: Mathew R. <mat...@ne...> - 2005-12-01 22:44:07
|
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=20 template-variables, it is your responsibility to "publish" the variable=20 names and their meaning, it is not up to the template designer to=20 "figure out" what they are and what they represent. That said, there is a justified argument for wanting something like a=20 <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/~mathe= w Boon Chew wrote: > I want a way to quickly display all the info in a var - a Dumper=20 > output if you will. But more than that, like in some other=20 > server-side language, you can query the column lists (or hash keys)=20 > and loop through those and use a piece of generic code when all you=20 > intend to do is to display everything in the var. > > Imagine yourself wanting to output all the info in a reference to an=20 > array of hashes (which essentially mimics a database table), the HTML=20 > code can really be made the same if a construct is available to loop=20 > through things. > > The tight coupling of knowledge between what's being sent from the=20 > perl code and the HTML can be avoided, that's the whole point of the=20 > design of the template module (vs Mason where you mingle Perl code=20 > with display code) right? It just seems ugly when I have to tell a=20 > designer to go look at the perl file to see what he is getting in the=20 > 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-template-use= rs >> >> >> ------------------------------------------------------------------= ------ >> *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.com%20= >=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 |