Theme composition pattern with Hugo?

I think this question is related to How to include the "next" partial in the search path?. That solved the case extending exactly one theme once, but how do I layer themes?

Specifically, what I’m trying to do is a setup of:

[site specific] --> [optional theme variant] --> [base theme]

In this case both the specific site, the variant, and the base theme all need to include things in the <script> tag in the footer. The base theme provides an empty partials/foot-extra to allow extension, but this only allows either the variant or the specific site to overwrite the foot-extra. I could solve this by having the optional middle layer overwrite partials/foot-extra and have that include a partials/foot-extra2 which the base site can overwrite, but then if I later remove the middle layer, nothing will include foot-extra2, and the site will break.

What is the design pattern in Hugo for optional middle layers?

Isn’t it simple? If you want the “variant” version to be used, delete/rename that partial in your “specific site”.

If you want the “specific site” version, that’s what it will happen by default if the partial is named same as that in the “base”.

Not quite, I want both to be used. The goal would be to have a partial (or whatever) for foot-extra that are the set of things that need to be added to the footer. The specific site adds some things as well as the optional theme.

If the specific site wants to use the optional middle layer, then it sets theme = "optional" in config.toml. If the optional middle layer is not in use, then it sets theme = "base".

The critical property here is that the only change for the specific site is the theme key. Remembering to change all of the intermediate partials in the specific feels like a recipe to forget to rename a few and miss them.