Perhaps you are looking at the wrong tool to solve this problem.  Personally I
never use TMPL_VARs to fill out my forms.  I use HTML::FillInForm to do it for
me.  This would solve your problem and simplify your templates (no need for the
tmpl_if mess to select an option in a selection box).  With HTML::FillInForm you
just create your select list statically in the template (or dynamically with
HTML::Template if you want).  Then once you get your $template->output, send it
to HTML::FillInForm and pass it either a hash of the form field values or just
pass the CGI query object, and it will parse your HTML and fill out the form for
you.

This adds an extra step in your code, and will impact performance since
HTML::FillInForm has to parse the HTML to fill in the form, but in most of my
apps this is acceptable.  A simple example follows:

my $query = new CGI;
my $template = new HTML::Template(...);
my $fif = new HTML::FillInForm;

my $html = $fif->fill(scalarref => \$template->output(),
                      fobject   => $query);

Cheers,

Cees

Quoting Mark Fuller <[EMAIL PROTECTED]>:

> > From: "Sam Tregar" <[EMAIL PROTECTED]>
> > Are you saying you can't do this now?  I've produced <select> boxes
> > with HTML::Template.  It requires a nasty pile of <tmpl_if> logic but
> > it's doable.
> 
> Hi Sam. Yes, I think "tmpl_if" will work. The problem I have is that my
> templates will be organized by spoken language. The english ones in a "en"
> directory. Spanish in "es" directory. My script will determine which
> templates to access depending on the visitor's language preference.
> 
> Now, in a template I might have an option box for "male or female". In
> Spanish, "hombre or mujer." This language difference is kept in the
> template, and an ordinal is used to communicate to the scripts what the
> choice was. Regardless of language, "1" is a male, and "2" is a female. So,
> in this case, it would defeat the strength of templates to call some other
> device to emit the option box. I'd have to store the language text in a
> MySQL table and pass it to the device that will create the option box. I'd
> rather not do that since the text logically belongs in the template instance
> for that language.
> 
> So, yes, I could set a param name for "one" and "two" and "three". Which
> ever is set to boolean true, that would be the option line to get the
> "selected" attribute. But, that seems like a difficult way to do it. The
> conditional test for string value (in template::expression) would be easier.
> I could set a single param to "two" and in the template test for "one" or
> "two" or "three". One param name with different values. It just seemed like
> template::expression gave me *a lot* more things which, at this point, I
> agree are undesireable.
> 
> Now that I think about it, I believe I could set a param name for "one" and
> "two" and "three" but instead of making them true and false (and using an if
> statement) I could set the correct one to "selected" and just let each
> variable be replaced by its value. Only one would have "selected" and it
> would be emitted at the correct option line.
> 
> Do you know if it would be more efficient to set one var and use a
> conditional to determine which option select line to treat differently. Or,
> set many vars and let them all be replaced (to null except one).
> 
> Thanks,
> Mark
> 
> 
> 
> -------------------------------------------------------
> This SF.net email sponsored by: Enterprise Linux Forum Conference & Expo
> The Event For Linux Datacenter Solutions & Strategies in The Enterprise 
> Linux in the Boardroom; in the Front Office; & in the Server Room 
> http://www.enterpriselinuxforum.com
> _______________________________________________
> Html-template-users mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/html-template-users
> 




-------------------------------------------------------
This SF.net email sponsored by: Enterprise Linux Forum Conference & Expo
The Event For Linux Datacenter Solutions & Strategies in The Enterprise 
Linux in the Boardroom; in the Front Office; & in the Server Room 
http://www.enterpriselinuxforum.com
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to