HUGO
News Docs Themes Community GitHub

OutputFormats

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

Syntax

PAGE.OutputFormats

Returns

[]OutputFormat

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 OutputFormats method on a Page object returns a slice of OutputFormat objects, 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.

(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.

(string) Returns the relative permalink of the page generated by the current output format.

Example

To link to the RSS feed for the current page:

{{ with .OutputFormats.Get "rss" }}
  <a href="{{ .RelPermalink }}">RSS Feed</a>
{{ end }}

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

<a href="/index.xml">RSS Feed</a>

Please see the link to output formats section to understand the importance of the construct above.