Is there a variable exposing the value of theme defined in config?

I tried .Site.Theme, but it looks like it is not in the list of Site variables.

I can redefine it as a Param, but that makes 2 entries to change.

No it isn’t. And if it was, you can configure many themes so it would potentially be a tree structure.

Ok, I understand the multi-themes issue.

Let me be more specific. Is there a way to know the theme used at a page level, to use in a layout or shortcode?

No, but you can “fake” it if you have access to the theme (as in are the theme developer): add a params section to your themes config.toml file:

themename = "themename"

This will be available if it’s not overridden in your users own config-params-section as site.Params.themename.

There is no integrated way to know what the current theme or theme folder is.

Yes, that’s what I had in mind initially. Was wondering if there is a standard option though, not to duplicate the name in two variables.

I think there is a very abstract thinking behind this: “Does YOUR THEME need to know which theme is in use? Then let YOUR THEME do the job.” :wink: It’s a very strict separation of programming logic and theme, but I never really required to “know” before what the theme is. Now using Go Modules this might be a completely different topic.

Your solution is either to hack it or to venture into the issues section of the Hugo Github repo and try to get this implemented as a proposal. I read quite often here about “how do I know what theme I am in” so it might be a useful feature if it can be implemented with not too much dev-time. The question really is “does the Hugo world need this” and I am not on that side of the issue :slight_smile: I am also not that important :wink:

PS: By the way, you never really described what you need this feature for. If you want to know if the current theme has a certain template, then have a look at template.Exists.

I needed it to check the presence of some images in the theme and then use imageConfig to load their parameters. This require to recreate the path of the images, and for this I need a string with the theme. It is a minor thing, but I did not want to let the theme name hard-coded into a small partial.

I just implemented your solution with a params at theme level, so at least is is more easily accessible.

If @bep thinks it is worth adding a readonly variable, I guess at the page level, I am happy to open a GitHub proposal documenting it.

Does this help? It works from the repo root.

Are you creating a theme, or working with a theme created by someone else?