Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support layout templates for all page kinds #12988

Open
akbyrd opened this issue Oct 27, 2024 · 5 comments
Open

Support layout templates for all page kinds #12988

akbyrd opened this issue Oct 27, 2024 · 5 comments
Labels
Milestone

Comments

@akbyrd
Copy link

akbyrd commented Oct 27, 2024

Use case: I want to make a single layout template that applies to both section and page kinds.

I have a custom output format for Atom feeds and a template to render them.

Currently I need to create both layouts/_default/list.atom.xml and layouts/_default/single.atom.xml. However, as far as I can tell RSS is hard coded with a special case for layouts/_default/rss.xml where the page kind is not required. This is great - I propose the same behavior for all layout templates.

If I try to write the valid template locations for home and section page kinds it looks something like this:

home

layouts[/{<type>|_default}]/{<layout>|index|<kind>|list}.<format>
optional for RSS            ^---------------------------^

section

layouts/{<type>|<section>|<kind>|/_default}/{<layout>|<section>|<kind>|list}.<format>
optional for RSS                            ^-------------------------------^

Where {a|b} means one of several values, [] means optional, and <> means a value replaced by page data. Not 100% accurate and I've left out a lot of detail, but I think close enough for this discussion.

For the part I've marked as optional for RSS it would be great if it were optional for other layout templates as well.

This is added functionality, so is less likely to break existing sites. It also seems like it might make the template locations slightly easier to understand since it's more consistent.

@jmooring
Copy link
Member

jmooring commented Oct 30, 2024

layouts/_default/rss.xml where the page kind is not required

rss is both a page kind and an output format, so we have a lookup order that is inconsistent and perhaps confusing when compared to other output formats. It sounds like this is a legacy thing that we continue to support for backwards compatibility. See #12992 (comment).

If I could wave a magic wand and somehow not break existing sites, rss would not be a page kind, and the lookup order for the rss output format would be consistent with everything else.1

I understand the desire to have one template handle all page kinds, but the purpose of a template named html.html is, at least to me, unclear. Which is why I don't like rss.xml either.

If the baseof template could function without the base/block construct, something like baseof.atom.xml makes sense to me, but I have no idea if that would even be possible given the different context passed to each template type (e.g., Page.Pages, Page.Data.Term, etc.).

Footnotes

  1. I would also change the page kind page to single, since everything's a page.

@bep
Copy link
Member

bep commented Oct 30, 2024

I understand the desire to have one template handle all page kinds, but the purpose of a template named html.html is, at least to me, unclear. Which is why I don't like rss.xml either.

The main purpose is, as I see it, to preserve the file extension to make the file editor happy. A common setup would be to have multiple output formats with the same output format (e.g. amp.html and ... html.html, search.json data.json ...) but different templates. Of course, html.html looks odd, but that's how it is.

If the baseof template could function without the base/block construct, something like baseof.atom.xml

Baseof templates does not work without the base/block construct, but baseof.atom.xml works fine (base/block could work nicely with base/block, I guess).

@bep bep removed the NeedsTriage label Oct 30, 2024
@bep bep added this to the v0.139.0 milestone Oct 30, 2024
@bep
Copy link
Member

bep commented Oct 30, 2024

rss is both a page kind and an output format,

I think it's safe to say that rss was a page kind at some point.

@jmooring
Copy link
Member

Well, this still works...

disableKinds = ['rss']

So it sure looks like a page kind, even if it isn't under the hood.

@bep
Copy link
Member

bep commented Oct 30, 2024

So it sure looks like a page kind, even if it isn't under the hood.

No, it isn't. See https://gohugo.io/getting-started/glossary/#page-kind

We have code in place to make old sites work, which I think I commented about in #12992.

@bep bep modified the milestones: v0.139.0, v0.140.0 Nov 21, 2024
@bep bep modified the milestones: v0.140.0, Unscheduled Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@jmooring @bep @akbyrd and others