AlternativeOutputFormats
Syntax
Returns
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.
Methods
Get IDENTIFIER
(any) Returns the OutputFormat object with the given identifier.
MediaType
(media.Type) Returns the media type of the output format.
MediaType.MainType
(string) Returns the main type of the output format’s media type.
MediaType.SubType
(string) Returns the subtype of the current format’s media type.
Name
(string) Returns the output identifier of the output format.
Permalink
(string) Returns the permalink of the page generated by the current output format.
Rel
(string) Returns the rel value of the output format, either the default or as defined in the site configuration.
RelPermalink
(string) Returns the relative permalink of the page generated by the current output format.
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.">
