hugo/docs/content/en/methods/page/AlternativeOutputFormats.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

1.3 KiB

title description categories keywords action
AlternativeOutputFormats Returns a slice of OutputFormat objects, excluding the current output format, each representing one of the output formats enabled for the given page.
related returnType signatures
methods/page/OutputFormats
page.OutputFormats
PAGE.AlternativeOutputFormats

{{% include "methods/page/_common/output-format-definition.md" %}}

The AlternativeOutputFormats method on a Page object returns a slice of OutputFormat objects, excluding the current output format, each representing one of the output formats enabled for the given page.. See details.

Methods

{{% include "methods/page/_common/output-format-methods.md" %}}

Example

Generate a link element in the <head> of each page for each of the alternative output formats:

<head>
  ...
  {{ $title := printf "%s | %s" .Title site.Title }}
  {{ if .IsHome }}
    {{ $title = site.Title }}
  {{ end }}
  {{ range .AlternativeOutputFormats -}}
    {{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink $title | safeHTML }}
  {{ end }}
  ...
</head>

On the site's home page, Hugo renders this to:

<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml" title="ABC Widgets, Inc.">