hugo/docs/content/en/functions/fmt/Printf.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

840 B

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

{{% include "functions/fmt/_common/fmt-layout.md" %}}

{{ $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">