mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
39
docs/content/en/functions/fmt/Printf.md
Normal file
39
docs/content/en/functions/fmt/Printf.md
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
title: fmt.Printf
|
||||
description: Formats a string using the standard `fmt.Sprintf` function.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [printf]
|
||||
related:
|
||||
- functions/fmt/Print
|
||||
- functions/fmt/Println
|
||||
returnType: string
|
||||
signatures: ['fmt.Printf FORMAT [INPUT]']
|
||||
aliases: [/functions/printf]
|
||||
---
|
||||
|
||||
{{% include "functions/fmt/_common/fmt-layout.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ $var := "world" }}
|
||||
{{ printf "Hello %s." $var }} → Hello world.
|
||||
```
|
||||
|
||||
```go-html-template
|
||||
{{ $pi := 3.14159265 }}
|
||||
{{ printf "Pi is approximately %.2f." $pi }} → 3.14
|
||||
```
|
||||
|
||||
Use the `printf` function with the `safeHTMLAttr` function:
|
||||
|
||||
```go-html-template
|
||||
{{ $desc := "Eat at Joe's" }}
|
||||
<meta name="description" {{ printf "content=%q" $desc | safeHTMLAttr }}>
|
||||
```
|
||||
|
||||
Hugo renders this to:
|
||||
|
||||
```html
|
||||
<meta name="description" content="Eat at Joe's">
|
||||
```
|
Reference in New Issue
Block a user