Re: populating dropdown box from db

Theunis De Klerk <theunis-xn/[email protected]>
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
On 5/9/2012 4:43 PM, Mark Haney wrote:
> in the HTML template:
>
>> [% FOREACH factory IN factory %]
>> <p style="text-align: left;"><strong>Select 
>> Factory:</strong><br><select name="factory"><OPTION>
>> <option value=some_value>$factory</option>
>> </select>
>> <input class="button" type="submit" value="Run Report">
>>
>> </form>
>
>
> Is this the proper way to do this, or is there a better/more flexible 
> way?  Am I missing something?
>
Hi,

So does this work?
[% FOREACH factory IN factory %]  (Note plural in example below)

I am also new to TT. But I would have done it like this :

#PERL
my $vars = { 'factories' => \@rows};

#HTML
<select name="factory">
[% FOREACH factory IN factories %]
<option value="">[% factory %]</option>
[% END %]
</select>

I am not sure why you would want to wrap the FOREACH around the select. 
Maybe I am missing something.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.