Check for the existence of a partial in project and theme components

I’m building a theme components which would ideally let the users customize partials depending on the content type.

  • partials/head.html
  • partials/post/head.html
  • partials/whatever/head.html

I need to check for the presence of the type partial in their layout hierarchy before using it of course and potentially fallback on the default.

This used to be simple when only the project’s could overwrite partials, but now that any other theme component can, using fileExists on on the project’s layouts/partials/ dir is not enough.

Any one stumbled on this issue since the implementations of theme-components? Is there a safe and not too overkilling way to do this?


1 Like


But I have it on my mental list of stuff fix. I guess we need to create some kind of “canonical filesystem” that is included when you do fileExists etc. A filesystem that include layouts below layouts (even if the project has configured something else).

But, as is it now, what you want isn’t possible.

But, as is it now, what you want isn’t possible.

Thanks. I guess for my use case a simple warning on the README can suffice.

Though out of curiosity, would limiting this to partials only with something like partialExists make this any more doable?

templateExists is actually a good idea. That would not involve the file system. You would have to create a GH issue.

1 Like

Note that I renamed it to the more general name so it can also be used for shortcodes or whatever.

Gladly did

1 Like