mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
9b0050e9aa
git-subtree-dir: docs git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
840 B
840 B
title | description | categories | keywords | action | aliases | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fmt.Printf | Formats a string using the standard `fmt.Sprintf` function. |
|
|
{{% 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">