in reply to HTML::Template and checking arbitrary radio buttons
There's no reason the same logic couldn't apply to your radio buttons -- have some facility to simply generate them inside your program (using CGI.pm or otherwise), and just use the results as a string to pass to a TMPL_VAR. Just make sure your application logic doesn't suffer because of it, i.e., still keep the HTML generation far away from the application logic. I swear I've seen threads about this very subject (with regard to <select> tags), but haven't been able to locate them. You may have better luck with your search terms.
Assuming it's feasable to alter the templates you currently have in use to facilitate another TMPL_* tag, a very slick way to do this would be to wrap your HTML::Template calls in a pre-parser that will make the following simple translation:
Notice the addition of TMPL_RADIO. Take a gander at the filter argument to HTML::Template->new, which would allow you to do just this. Now when you (or your designers) edit the templates, they see one atomic TMPL_* tag without the ugliness of the TMPL_IF, the application code shouldn't need to be changed, and the nested tags don't show up until right before the HTML is passed to HTML::Template.# change this in your template: <TMPL_RADIO PARAM="foo1" NAME="foo" VALUE="1"> <TMPL_RADIO PARAM="foo2" NAME="foo" VALUE="2"> # to this: <input type=radio name="foo" value="1" <TMPL_IF NAME="foo1">checked</TMPL_IF>> <input type=radio name="foo" value="2" <TMPL_IF NAME="foo2">checked</TMPL_IF>>
Best of luck,
blokhead
|
|---|