hugo/docs/content/en/functions/fmt/Printf.md
2023-10-20 09:43:56 +02:00

992 B

title linkTitle description categories keywords menu function relatedFunctions aliases
fmt.Printf printf Formats a string using the standard `fmt.Sprintf` function.
functions
docs
parent
functions
aliases returnType signatures
printf
string
fmt.Printf FORMAT [INPUT]
fmt.Print
fmt.Printf
fmt.Println
/functions/printf

The documentation for Go's fmt package describes the structure and content of the format string.

{{ $var := "world" }}
{{ printf "Hello %s." $var }} → Hello world.
{{ $pi := 3.14159265 }}
{{ printf "Pi is approximately %.2f." $pi }} → 3.14

Use the printf function with the safeHTMLAttr function:

{{ $desc := "Eat at Joe's" }}
<meta name="description" {{ printf "content=%q" $desc | safeHTMLAttr }}>

Hugo renders this to:

<meta name="description" content="Eat at Joe's">