HUGO
Menu
GitHub 86567 stars Mastodon

AlternativeOutputFormats

Returns a slice of OutputFormat objects, excluding the current output format, each representing one of the output formats enabled for the given page.

Syntax

PAGE.AlternativeOutputFormats

Returns

page.OutputFormats

An output format is a collection of settings that defines how Hugo renders a file when building a site. For example, html, json, and rss are built-in output formats. You can create multiple output formats and control their generation based on page kind, or by enabling one or more output formats for specific pages.

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.

For example, to generate a link element for each of the alternative output formats:

{{ range .AlternativeOutputFormats }}
  {{ printf "<link rel=%q type=%q href=%q>" .Rel .MediaType.Type .Permalink | safeHTML }}
{{ end }}

Hugo renders this to something like:

<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml">
<link rel="alternate" type="application/json" href="https://example.org/index.json">