AlternativeOutputFormats
Syntax
PAGE.AlternativeOutputFormats
Returns
page.OutputFormats
Hugo generates one or more files per page when building a site. For example, when rendering home, section, taxonomy, and term pages, Hugo generates an HTML file and an RSS file. Both HTML and RSS are built-in output formats. Create multiple output formats, and control generation based on page kind, or by enabling one or more output formats for one or more pages. See details.
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 theOutputFormat
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 therel
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.">