Rss.xml template inheritance

I really hope this isn’t asked and answered already, but I haven’t found it yet.

What I want to do is to have section and subsection specific RSS feeds. However, it appears that regardless of what I put in separate rss.xml files layouts for the different sections and subsections, they all inherit and use /layouts/rss.xml.

Is there a way to override this and actually get a section and subsection specific RSS feed?

To clarify, the reason I need to do this is because I have the following layout:

content
|–blog
| |-----iOS
| |-----mac
|–podcasts
| |-----dnia
| |-----psp

I want my RSS feed for blog to have all entries for itself AND /blog/ios and /blog/mac. Also I want my RSS feed for /podcasts to have all entries for /podcasts/dnia and podcasts/psp if I choose.

I also have an RSS feed template in /layouts/rss.xml to appear in the site root which uses the following query:

{{ range where .Site.RegularPages “Type” “blog” }}

This lets me have a sitename/feed.xml which all blog posts in it, which I want. But consequently, all my section and subsection RSS feeds seem to inherit this, regardless of what I put in /layouts/blog/rss.xml and /layouts/blog/ios/rss.xml and /layouts/blog/mac/rss.xml, etc etc.

I want my /layouts/blog/rss.xml file to also use the same query as /layouts/rss.xml, ie

{{ range where .Site.RegularPages “Type” “blog” }}

But I want the subsection ones in /layouts/blog/ios and /layouts/blog/mac to have use

{{ range .RegularPages }} or {{ range .RegularPages “Type” “ios” }} or whatever.

Obviously I don’t want those subsections to inherit the /layouts/rss.xml and therefore show all posts from every /blog subsection.

I have looked at both the custom output and the template lookup order docs, and I’m still hitting this issue.

Thank you.

1 Like

Probably best if you show what you’ve done. :slight_smile:

added above

The automatic section assignment in Hugo is first level only /blog /podcast. If you want to assign Type to nested sections (mac etc.), you need to set it in front matter, and for it to stick to all descendants, use the cascade keyword.

3 Likes

A related tip to get more plortable templates is to use .RegularPages in the list templates, which should give you the current section’s pages (one level only).

3 Likes

To clarify:

  • Hugo does support nested sections
  • But the .Section variable (as used in the where clauses above) is set to the first level
1 Like

Okay… I think I finally got this.

They key is in layouts, don’t nest the section folders.

For example, if in content, you have

/content/blog
/content/blog/subsection1, 
/content/blog/subsection2 
/content/blog/subsection3 

then put an _index.md inside each of those subsections with the type (type = “subsection1” etc etc).

Then in /layouts, don’t nest them. Have this:

/layouts/blog
/layouts/subsection1
/layouts/subsection2
/layouts/subsection3

Then the template for the subsection RSS feeds is just {{ range .RegularPages }} and the template for the /blog section RSS can be a range that is a union of all your section types.

2 Likes