You can use printf
in templates, which acts as fmt.Sprintf
. In your case truncating a string would be as easy as:
{{ printf "%.25s" .Content }}
You can also pass the number as a separate integer argument to printf
:
{{ printf "%.*s" 25 .Content }}
Note from the documentation:
Width and precision are measured in units of Unicode code points, that is, runes. (This differs from C’s printf where the units are always measured in bytes.)