in reply to Re: How do you use Template Toolkit with Dancer2?
in thread How do you use Template Toolkit with Dancer2?
<select name="[% name %]" > [%- FOR option IN options %] <option [% FOREACH attr IN option.attributes.keys %][% attr %]="[% opt +ion.attributes.$attr %]" [% END -%] [%- IF option.default %]selected="selected" [% END -%] value="[% option.value %]">[% option.label %]</option> [%- END %] </select>
In Dancer2 code, just call it with
return template 'menu', {name => 'menu_name', options => [ {value => 'eenie', label => 'your first choice', attributes +=> {class => 'first choice'}}, {value => 'meenie', label => 'your second choice', default => + 1}, {value => 'minie', label => 'your third choice', default => + 1}], }
Update: Accept any attributes, not just class (not sure I'd recommend it).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How do you use Template Toolkit with Dancer2?
by PiotrS (Novice) on Apr 27, 2022 at 13:54 UTC | |
by choroba (Cardinal) on Apr 27, 2022 at 18:36 UTC | |
by PiotrS (Novice) on Apr 29, 2022 at 01:07 UTC | |
by choroba (Cardinal) on Apr 29, 2022 at 07:30 UTC |