HUGO
Menu
GitHub 90418 stars Mastodon

fmt.Warnf

Logs a WARNING from a template.
Syntax
fmt.Warnf FORMAT [INPUT]
Returns
string
Alias
warnf

Usage

The fmt.Warnf function logs a WARNING from a template. The function formats INPUT according to FORMAT and writes the result to the WARNING log. The function returns an empty string.

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

To avoid flooding the log with duplicate warnings, Hugo logs each unique message once. When you use the fmt.Warnf function for debugging, make each message unique with the math.Counter function to log every message.

To allow suppression of specific warnings, use the fmt.Warnidf function instead.

Examples

{{ fmt.Warnf "The %q shortcode was unable to find %s. See %s" .Name $file .Position }}

Making each message unique for debugging:

{{ range site.RegularPages }}
  {{ .Section | fmt.Warnf "%#[2]v [%[1]d]" math.Counter }}
{{ end }}