Re: [htmltmpl] loop through a hash structure without knowing the hash keys?
Brought to you by:
samtregar
From: Mathew R. <mat...@ne...> - 2005-12-08 02:08:20
|
As a thought, you could try something like this: print Dumper($ht->{param_map}); I haven't tested it, but it may work... Mathew Boon Chew wrote: >Thanks Carl, useful tip. Taking your idea one step >further, I think having an option such as > >show_all_params =3D> 1 that shows all the params passed >to the template in a Dumper fashion will be quite >useful. > > >- boon > >--- Carl Franks <fir...@gm...> wrote: > > =20 > >>If you make sure >>die_on_bad_params =3D> 1 >>is set in your HTML::Template constructor, then any >>variable which >>isn't set in the template, or is misspelt will cause >>the page to die - >>the designer can then tell what's wrong by simply >>looking at the error >>message. >> >>Carl >> >> >>On 02/12/05, Boon Chew <was...@ya...> wrote: >> =20 >> >>>Well, I guess I should have explained the need of >>> =20 >>> >>this >> =20 >> >>>with a more solid real world use case. >>>Recently I am involved in a project using Krang, a >>> =20 >>> >>CMS >> =20 >> >>>system written in Perl that utilizes >>> =20 >>> >>HTML::Template. >> =20 >> >>>Now here is the thing, we are fairly new to the >>> =20 >>> >>code >> =20 >> >>>base, but in a few days of going through the code >>> =20 >>> >>and >> =20 >> >>>poking around the code, we were able to implement >>>quite a few new features for the client. >>> >>>But our understanding of the system is still >>> =20 >>> >>immature >> =20 >> >>>and incomplete, and there are times the template >>> =20 >>> >>var >> =20 >> >>>is being set somewhere in the inheritance chain, >>> =20 >>> >>and >> =20 >> >>>we know a template can access a specific variable >>>(through incomplete doc and tmpl_if test), but >>> =20 >>> >>there >> =20 >> >>>is no way to know how to access the variable >>> =20 >>> >>without >> =20 >> >>>going through the code tracing out where and what >>> =20 >>> >>is >> =20 >> >>>sent to the template. And what if the >>> =20 >>> >>documentation >> =20 >> >>>misses talking about a var that is sent to the >>>template? No one you can find out unless you poke >>>around the code, but the process can be time >>> =20 >>> >>consuming >> =20 >> >>>as not all the templates are being set in one file >>>(due to OO). >>> >>>I find it surprising that people expect problems >>> =20 >>> >>can >> =20 >> >>>be solved with documentation, or communication >>> =20 >>> >>with >> =20 >> >>>the frontend folks. In the real world, >>> =20 >>> >>documentation >> =20 >> >>>is never as complete as should, I mean, it's hard >>>enough to get some to comment their code! And in >>> =20 >>> >>the >> =20 >> >>>real world, you don't always start a project with >>> =20 >>> >>code >> =20 >> >>>that you have written as well. The need to be >>> =20 >>> >>able to >> =20 >> >>>introspect and access what is sent to the template >>>without having the perl code is a useful and >>>justifiable feature of any server-side scripting >>>framework. >>> >>> >>>- boon >>> >>>--- "Webmaster Techcode.NET" >>> =20 >>> >><web...@te...> >> =20 >> >>>wrote: >>> >>> =20 >>> >>>>----- Original Message ----- >>>>From: Boon Chew >>>> >>>>I want a way to quickly display all the info in >>>> =20 >>>> >>a >> =20 >> >>>>var - a Dumper output if you will. But more >>>> =20 >>>> >>than >> =20 >> >>>>that, like in some other server-side language, >>>> =20 >>>> >>you >> =20 >> >>>>can query the column lists (or hash keys) and >>>> =20 >>>> >>loop >> =20 >> >>>>through those and use a piece of generic code >>>> =20 >>>> >>when >> =20 >> >>>>all you intend to do is to display everything in >>>> =20 >>>> >>the >> =20 >> >>>>var. >>>> >>>>----- Original Message ----- >>>> >>>>I agree - something like Data::Dumper in >>>>HTML::Template context would be great. >>>> >>>>And you can also "you can query the column lists >>>> =20 >>>> >>(or >> =20 >> >>>>hash keys) and loop through those" in Perl just >>>> =20 >>>> >>like >> =20 >> >>>>in any other server-side language ... >>>> >>>>foreach(@array){ >>>> print $_,"\n<br>"; >>>>} >>>> >>>> >>>> >>>>----- Original Message ----- >>>>The tight coupling of knowledge between what's >>>> =20 >>>> >>being >> =20 >> >>>>sent from the perl code and the HTML can be >>>> =20 >>>> >>avoided, >> =20 >> >>>>that's the whole point of the design of the >>>> =20 >>>> >>template >> =20 >> >>>>module (vs Mason where you mingle Perl code with >>>>display code) right? It just seems ugly when I >>>> =20 >>>> >>have >> =20 >> >>>>to tell a designer to go look at the perl file >>>> =20 >>>> >>to >> =20 >> >>>>see what he is getting in the var. He should be >>>>able to find that out fro m some sensible >>>>constructs. >>>>----- Original Message ----- >>>> >>>>You missed the point ... >>>> >>>>I mean - designer shouldn't need to take a look >>>> =20 >>>> >>at >> =20 >> >>>>Perl code to figure out what you are outputing >>>> =20 >>>> >>... >> =20 >> >>>>And "some sensible constructs" are documents >>>> =20 >>>> >>that >> =20 >> >>>>folow every project. Have you ever heared of >>>> =20 >>>> >>terms >> =20 >> >>>>like API or Interface? You and you designer need >>>> =20 >>>> >>to >> =20 >> >>>>agree on "Interface" - in your case the data he >>>> =20 >>>> >>can >> =20 >> >>>>use in the template ... >>>> >>>>Anyway - the quick and simple solution that just >>>>crossed my mind ;) >>>> >>>>Make something a rule - for each template - you >>>>could create a special variable. Say you can >>>> =20 >>>> >>name it >> =20 >> >>>>: "the_dump" or whatever. >>>>And simply dump via Data::Dumper all variables >>>> =20 >>>> >>that >> =20 >> >>>>you (plan) populate the template with - or send >>>> =20 >>>> >>to >> =20 >> >>>>template. >>>> >>>>Actualy - this could be made as part of >>>>HTML-Template ... >>>> >>>>Anyway - then your designer could just add >>>> =20 >>>> >><tmpl_var >> =20 >> >>>>name=3D"the_dump"> at the end of the template if >>>> =20 >>>> >>he is >> =20 >> >>>>not sure what data he can access. >>>> >>>>Of course - next thing he will complain is why >>>> =20 >>>> >>in >> =20 >> >>>>the hell he can't do a preview in Dreamweaver >>>> =20 >>>> >>with >> =20 >> >>>>test data already populated ... >>>> >>>>Cheers, >>>>Alex. >>>>N=18=ACHY=DE=B5=E9s(S(X=AC=B2s('=B2S(=DEu=BC'=A6[=A7?0/00=DC=0EOE=A8=BA= >>>>=DE=A6=D8k=A2=E8!-^=1FS(W=AC~S(=E9(r)+=E5zk=12=B6S(C=A3 >>>> =20 >>>> >=E5=A1=A7m...=E9=DE=C0=02@^=C7s(=AD=C8^z(=08=A7z=D8Z=B6f=A4z=CB=1Ej=B7!S= (x2=A2=EA=E5=A2=07=E2.=EB=1A=B1=E6=AC=C9=AB,=BA=B7=E2z(=0Ba{=07>=0C=E5?,=E0= =03H=F2=D44=A8m=B6Y"=FFi=DB(=B1=D9=DC=A2o=DAv'=EF=AD=FBjYhr'=D7=AF:=E6S(r= Xoe?{f-=D7=A6=A6V=ADz=EB=1E(r)=C9s(S(X=A7,X=AC=B4{f-=D7=A6=A6V=ADz=EB=1E(= r)=C9b=B2=DB,=A2=EA=DCy=FA+?=E9=DE=B6=1Bm=A6=CF=FF-+-=B2=CA.=AD=C7Y"=A2=B8= =1E?=EB?-+-=B3=F9b=B2=D8=A7~?=E1=B6imzjej=D7(r)=B1=EA=EC > =20 > >>> >>> >>>__________________________________________ >>>Yahoo! DSL - Something to write home about. >>>Just $16.99/mo. or less. >>>dsl.yahoo.com >>> >>> >>> >>> >>> =20 >>> >------------------------------------------------------- > =20 > >>>This SF.net email is sponsored by: Splunk Inc. Do >>> =20 >>> >>you grep through log files >> =20 >> >>>for problems? Stop! Download the new AJAX search >>> =20 >>> >>engine that makes >> =20 >> >>>searching your log files as easy as surfing the=20 >>> =20 >>> >>web. DOWNLOAD SPLUNK! >> =20 >> >http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick > =20 > >>>_______________________________________________ >>>Html-template-users mailing list >>> =20 >>> >=3D=3D=3D message truncated =3D=3D=3D > > > > =09 >__________________________________=20 >Start your day with Yahoo! - Make it your home page!=20 >http://www.yahoo.com/r/hs > > >------------------------------------------------------- >This SF.net email is sponsored by: Splunk Inc. Do you grep through log f= iles >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_id=3D7637&alloc_id=3D16865&op=3Dclick >_______________________________________________ >Html-template-users mailing list >Htm...@li... >https://lists.sourceforge.net/lists/listinfo/html-template-users > =20 > |