How to truncate a string in a Golang template

后端 未结 7 558
轮回少年
轮回少年 2021-01-01 09:16

In golang, is there a way to truncate text in an html template?

For example, I have the following in my template:

{{ range .SomeContent }}
 ....
             


        
相关标签:
7条回答
  • 2021-01-01 10:18

    You can define a function. Take a look http://golang.org/pkg/text/template/#example_Template_func.

    Edit: See it at the playground: http://play.golang.org/p/OP2x5vDCtn

    0 讨论(0)
提交回复
热议问题