|Don't ask to ask, just ask|
Browser-viewable HTML::Template templatesby dws (Chancellor)
|on Jan 11, 2003 at 22:59 UTC||Need Help??|
I while back I posed a question about handling checkboxes and radio buttons in HTML::Template templates. I was looking for a scheme that de-coupled page design from application development, so that both could proceed in parallel. In particular, I wanted to be able to view templates directly in a browser (to verify design changes), while also supporting the ability to generate a page with specific radio boxes and check boxes checked.
A first glance, there are three approaches to generating pages that have specific boxes checked.
One either has to produce the HTML input tags in code, via
or one has to temporarily break the HTML in the template by doing
or one has to bloat the template with conditional logic
All of these approaches work, but none allow the unexpanded template to be viewed in a browser. In the first scheme you get an empty hole, the second scheme results in invalid HTML, and the third scheme shows each input control twice.
I didn't find a clean scheme, but did settle on a hybrid one that works.
When the initial page design is templatized,
gets turned into
with $template->param(false => 0);
When viewed in a browser, the original input tag is displayed. But when the template is expanded, the tag in the template gets discarded and a dynamically generated tag takes its place.
The downsides of this scheme are that HTML is being produced in code, and that template designers need to coordinate changes with the application developers (which is true anyway). But it works, and it also works when generating dynamic pop-up menus using select tags.
If anyone has a better approach, I would love to hear about it.