Skip to content

Move partials and shortcodes out of layouts #13626

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

Open
willfaught opened this issue Apr 19, 2025 · 4 comments
Open

Move partials and shortcodes out of layouts #13626

willfaught opened this issue Apr 19, 2025 · 4 comments
Labels
Milestone

Comments

@willfaught
Copy link
Contributor

(I didn't get a response to https://discourse.gohugo.io/t/hugo-v0-146-0-and-v0-146-1-released/54300/5?u=will, so I will carry over the unaddressed stuff from #13476 here.)


I never understood why they're in /layouts: they're not layouts. They also conflict with /content/partials and /content/shortcodes sections that have their own layouts. It also needlessly deepens the directory depth, making it slow to change directories or click around a file explorer.

Make /layouts/partials a fallback for /partials, then deprecate /layouts/partials.

Make /layouts/shortcodes a fallback for /shortcodes, then deprecate /layouts/shortcodes.


While we're at it, reconsider the names "partials" and "shortcodes". They're really general-purpose templates and templates for content, respectively. Perhaps partial -> template and shortcode -> snippet (snippets can be parameterized, as in the context of text editors)?

And while we're at it, rename baseof.html to base.html (or _base.html if needed in /layouts) with a deprecation like above.

@bep
Copy link
Member

bep commented Apr 19, 2025

I never understood why they're in /layouts: they're not layouts.

  1. They need to have a common root
    1. So we can have one view of all templates across themes (overlay file system)
    2. We need to easily resolve a file change to "what and where".
  2. The Go templates needs to be in one namespace, so they needs to be parsed in "one Go"; having them structured in the same directory makes this simpler to reason about.
  3. I don't think adding "more Hugo folders" to the will be any easier to explain to people,

While 1/2 may be possible with multiple roots, it would be very expensive to implement/change.

They also conflict with /content/partials and /content/shortcodes sections that have their own layouts.

We have renamed them _partials and _shortcodes for this very reason. The rewrite/redesign of the template system in Hugo 0.146 was very, very expensive. For us to even consider making structural changes to this setup it needs to be really valuable.

@bep bep added this to the Unscheduled milestone Apr 19, 2025
@willfaught
Copy link
Contributor Author

willfaught commented Apr 19, 2025

They need to have a common root 1. So we can have one view of all templates across themes (overlay file system)

Then shouldn't /assets also be under /layouts? Why can't the root directory be the common root?

  1. We need to easily resolve a file change to "what and where".

I don't see why these changes would preclude being able to do this?

I don't think adding "more Hugo folders" to the will be any easier to explain to people,

Don't _shortcodes and _partials have that same issue?

The rewrite/redesign of the template system in Hugo 0.146 was very, very expensive

Fair enough, but deciding not to do something because of implementation cost is different than deciding not to do something because it's a bad idea.

@tycobra
Copy link

tycobra commented Apr 21, 2025

Personally, I like the Hugo way of grouping partials and shortcodes within layouts. If in case the proposal to shift them is accepted, I would prefer if the current behaviour is maintained somehow, or made configurable.

@willfaught
Copy link
Contributor Author

I'll add that while the implementation cost might be too high for existing contributors, it might be motivational for newcomers (like me) to get involved.

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

3 participants