Include partial using full path

If I have multiple themes and I want to include a partial using a full path, can I do that?


I can copy things into ./layouts then. Bit of a bummer though.

I’ll elaborate just a bit, just in case anyone else finds their way to this thread.

I’ve found a few cases where there is a partial in a theme I’d like to use. I was considering adding a couple submodules to my themes directory, then using {{ partial "[path]" }} in my layouts to reference those snippets.

Alas, this is not possible. Hugo looks in two places for a partial.

  1. layouts/partials/*<PARTIALNAME>.html
  2. themes/<THEME>/layouts/partials/*<PARTIALNAME>.html

Maybe there’s another strategy I could use. For now, I’m just copying things into ./layouts/partials when I find something I like.

You asked me a very specific question.

We should probably improve on this, but if you have a theme with a partial with the same name as yours, yoy could mount the theme’s partial folder into some other folder (creating a namespace for it, so to speak).

Sym linking is a good idea. Thanks.

Nope. Stop right there.

I feel like you don’t see one prime thing about themes in Hugo.

You probably are using the theme configuration parameter. Look at themes instead. You can combine themes and overwrite partials by using the same name. I am sure you understood that in another thread where I responded. If you ever had to work with WordPress it’s the “child theme” system. You have a theme you like and add your own changes to it in themes: ["parenttheme", "childtheme"]. Then you overwrite everything you want to change in the parent theme in your child theme.

“Mounting” is not “symlinking” in the sense of linux. Careful here. But I guess themes will be enough for what you attempt to do.

1 Like

I do understand that. If I found a theme with a partial I wanted to use and I added it to the themes array, I might end up using more than just the partial I actually want.

I think it’s simplest just to copy things into ./layouts, which is effectively no different than making themes: ['theme', 'customchildtheme']. The root is essentially just that customchildtheme.

Two things I was initially thinking about trying to achieve were:

  1. Retaining the ability to get improvements in the partial by referencing it and getting those updates when I run git submodule update
  2. Not committing vendor code into my repo

Maybe bep wasn’t suggesting using a symlink, but it seems like a viable solution that meets my aforementioned needs. It would be more granular than adding it to the themes array.

  1. Include a theme that has something I want to use in themes as a git submodule
  2. Don’t put it in the themes array
  3. Symlink the part I want to use into customchildtheme that is in the themes array (or root)

I’m probably not communicating this as clearly as could be done by someone more eloquent, but I learned the things I wanted to through this discussion, and I greatly appreciate the time of the two of you who responded.

I’m loving Hugo. <3

Yep. In this whole system the only issue I encountered is when the theme is updated. I like to use “meld” ( to check for changes between files and folders. It’s showing nicely what is changed and you can decide what change to take over to your version of the theme file.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.