Different Templates for RSS

My theme uses a custom template for image shortcodes that enables js-powered lazy loading and a zoom overlay. That technique works fine in in web browsers, but is buggy in RSS readers, rendering duplicate images and markup that’s supposed to be hidden.
Is there a way to load a different template for RSS?
I tried setting a scratch flag at the beginning of the RSS template and checking for it in the image template, but I can’t seem to access it.

Here’s my image component: https://www.github.com/iamschulz/iamschulz-hugo-theme/tree/master/layouts%2Fpartials%2Fimage%2Fimage.html
And here’s my RSS template: https://www.github.com/iamschulz/iamschulz-hugo-theme/tree/master/layouts%2F_default%2Frss.xml

shortcodes/
├── image.html
└── image.rss.html

When you include {{< image >}} in your markdown, the image.html template will be used for HTML rendering, and image.rss.html will be used when creating the RSS feed.

2 Likes

Awesome, that did the trick. Thanks!
I couldn’t find that in the Docs. Did I just oversee it or is it missing?

1 Like

I couldn’t find it in the docs. It should be here: https://gohugo.io/templates/shortcode-templates/#shortcode-template-lookup-order. I’ll make a note to submit a PR in the near future.

I found it by searching through closed GitHub issues. I suspected it was possible, and wanted to confirm before trying. Then I tested before letting you know.

2 Likes

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