fmt.Printf
Syntax
fmt.Printf FORMAT [INPUT]
Returns
string
Alias
printf
Go的fmt包的文档描述了格式化字符串的结构和内容。
{{ $var := "world" }}
{{ printf "Hello %s." $var }} → Hello world.
{{ $pi := 3.14159265 }}
{{ printf "Pi is approximately %.2f." $pi }} → 3.14
使用printf
函数和safeHTMLAttr
函数:
{{ $desc := "Eat at Joe's" }}
<meta name="description" {{ printf "content=%q" $desc | safeHTMLAttr }}>
Hugo将其渲染为:
<meta name="description" content="Eat at Joe's">