Clear instructions on how to upgrade to the OutputFormats RSS

Hi, I recently upgraded from Hugo 0.55 to 0.70 and I started getting this warning:

Page.RSSLink is deprecated and will be removed in a future release. Use the Output Format’s link, e.g. something like:
{{ with .OutputFormats.Get “RSS” }}{{ .RelPermalink }}{{ end }}

Fine, so what’s what I did. I replaced the following code:

{{ if .RSSLink }}
  <link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
  <link href="{{ .RSSLink }}" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end }}

With this::

{{ with .OutputFormats.Get "RSS" }}{{ .RelPermalink }}{{ end }}

But that causes this “index.xml” label to appear at the top of my homepage:

I tried to keep the <link> tags in between the first pair of handlebars and the second pair, like this:

{{ with .OutputFormats.Get "RSS" }}{{ .RelPermalink }}{{ end }}
  <link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
  <link href="{{ .RSSLink }}" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end }}

But this didn’t compile at all. How can I apply the new syntax to my use case?

:thinking:

If your first snippet worked, then maybe try:

{{ with .OutputFormats.Get "RSS" }}
  <link href="{{ .RelPermalink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
  <link href="{{ .RelPermalink }}" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end }}

Unfortunately this didn’t work either. I got this error:

execute of template failed: template: partials/header.html:17:101: executing “partials/header.html” at <.Site.Title>: can’t evaluate field Site in type *page.OutputFormat

https://gohugo.io/templates/introduction/#the-dot
https://gohugo.io/functions/with/

with

Rebinds the context ( . ) within its scope…

Inside of the with structure, .Site.Title is non-existent.

{{ $foo := .Site.Title }}
{{ with .OutputFormats.Get "RSS" }}
  <link href="{{ .RelPermalink }}" rel="alternate" type="application/rss+xml" title="{{ $foo }}" />
  <link href="{{ .RelPermalink }}" rel="feed" type="application/rss+xml" title="{{ $foo }}" />
{{ end }}
1 Like

Now it worked! Thanks so much, @jmooring!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.