Before you hit the downvote, the question isn't as ludicrous as it may sound from the title.
Say I have Items and Categories. An item can belong to multiple categories.
I have a basic HTML form where a user fills out stuff to create an item and I also list all categories as a list of checkboxes (see code below) so that a user can check which category (one or many) the item being created should belong to.
So far all is well.
However, when a user edits this item, I'd of course like to show the categories checkbox list with the categories the item belongs to populated as checked so that you can easily see which categories the item currently belongs to, and uncheck if you like etc.
Sounds easy enough.
So, we would have something like the following queries in the controller (say, I want to edit item with id = 3)
1) SELECT * FROM Item WHERE Id = 3 (gets us the item we want to edit)
2) SELECT * FROM Categories WHERE 1 (gets ALL categories)
3) SELECT CategoryId FROM ItemCategories WHERE ItemId = 3 (gets the categoryids for the categories the item belongs to)
The HTML for showing the categories (all categories) would look something like this
<form>
...
{{range .Categories}}
<input name="cat" type="checkbox" value="{{ .Id }}" /> {{ .Title}} <br />
{{end}}
...
</form>
So, what I'd typically would like to have done is just to be able to, per category in the range, check if the Id exists in the ItemCategories result, and if so set it to checked in the HTML code. Since it's difficult to use a FuncMap for this, since it won't allow you to pass along the slice with the checked categories to the method, it becomes a bit of a challenge to see how this can be done in the presentation layer, given that you have the data you need.
Of course, I can do this in several ways in the controller (anything from merging the two results in second and third query as a struct, to building the HTML output there, passing it via the context to the HTML page) but as I'm still learning how to code in golang, I just wanted to check how others are going about solving this type of situation as it is quite generic in its nature (i.e. I will certainly come across it again).
Thanks.