I pass a struct to a template that sometimes contain strings that are a tad too long for display. In any other language, I would've just attached a formatting rule in the template itself. What's the idiomatic approach to accomplish formatting in templates?
Example:
type struct MyStruct{
something string
anotherThing string
}
In the template
<table>
{{ range .Rows }} //NOTE! Rows is an array of MyStruct objects
<tr>
<td>{{ .something }}</td>
<td>{{ .anotherThing }}</td>
</tr>
{{ end }}
</table>
In case it isn't obvious from the above, the question is "How would you go about making sure .anotherThing or .something doesn't display more than say 40 characters?
One solution COULD be to make the struct contain four values, the two raw strings and two formatted version of them i.e. make the formatting in the .go-file and then always display the raw string in a tooltip on hover or something like that.