{% import "strconv" %} {% code type searchField struct{ id, name string } %} Common seatch part of many pages {% func SearchCommon(search SearchForm) %} <select name="c" class="form-control input-sm" value> <option value="_">All categories</option> {%= searchOptions(search.Category, []searchField{ {"3_", "Anime"}, {"3_12", "Anime - Anime Music Video"}, {"3_5", "Anime - English-translated"}, {"3_13", "Anime - Non-English-translated"}, {"3_6", "Anime - Raw"}, {"2_", "Audio"}, {"2_3", "Audio - Lossless"}, {"2_4", "Audio - Lossy"}, {"4_", "Literature"}, {"4_7", "Literature - English-translated"}, {"4_8", "Literature - Raw"}, {"4_14", "Literature - Non-English-translated"}, {"5_", "Live Action"}, {"5_9", "Live Action - English-translated"}, {"5_10", "Live Action - Idol/Promotional Video"}, {"5_18", "Live Action - Non-English-translated"}, {"5_11", "Live Action - Raw"}, {"6_", "Pictures"}, {"6_15", "Pictures - Graphics"}, {"6_16", "Pictures - Photos"}, {"1_", "Software"}, {"1_1", "Software - Applications"}, {"1_2", "Software - Games"}, }) %} </select> <select name="s" class="form-control input-sm"> <option value="">Show all</option> {%= searchOptions(search.Status, []searchField{ {"2", "Filter Remakes"}, {"3", "Trusted"}, {"4", "A+"}, }) %} </select> {% endfunc %} Options fields of a search <select> element {% func searchOptions(selected string, s []searchField) %} {% for _, s := range s %} {%= searchOption(selected, s) %} {% endfor %} {% endfunc %} Single search optiion field of a <select> {% func searchOption(selected string, s searchField) %} <option value="{%s= s.id %}" {% if selected == s.id %}selected{% endif %}>{%s= s.name %}</option> {% endfunc %} {% func SearchAdvanced(nav Navigation, search SearchForm) %} <select name="sort" class="form-control input-sm"> {%= searchOptions(search.Sort, []searchField{ {"torrent_id", "ID"}, {"torrent_name", "Name"}, {"date", "Date"}, {"downloads", "Downloads"}, {"filesize", "Size"}, }) %} </select> <select name="order" class="form-control input-sm"> {%= searchOptions(search.Order, []searchField{ {"desc", "Descending"}, {"asc", "Ascending"}, }) %} </select> <select name="max" class="form-control input-sm"> {% code sel := strconv.Itoa(nav.MaxItemPerPage) %} {% for _, m := range [...]int{5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 70, 100, 150, 200, 300} %} {% code id := strconv.Itoa(m) %} {%= searchOption(sel, searchField{id, id}) %} {% endfor %} </select> {% endfunc %} {% func SearchButton(search SearchForm) %} <div class="input-group"> <input name="q" class="form-control input-sm" placeholder="Search" type="text" value="{%s search.Query %}"> <span class="input-group-btn"> <button type="submit" class="btn btn-sm btn-success"> <span class="glyphicon glyphicon-search" aria-hidden="true"></span> Search </button> </span> </div> {% endfunc %}