Skip to content

Instantly share code, notes, and snippets.

@BD3i
BD3i / selected_option.html.ep
Created January 11, 2024 12:46
mojolicious select_field with selected option
<%
# this version works with index based numeric value keys
# note if you're storing this numeric value somewhere,
# you can never re-order the values and can only add to the end of the list
my $home_shows = 2; # current value
my $i = 0;
my @options = map { $i == $home_shows ? [$_ => $i++, selected => undef] : [$_ => $i++] }
qw(latest popular profile);
%>
<label class="label" for="home-shows">home shows</label>