Check if default language content is in a language subdir?

Hi fellow Hugo-ites!

I have a Hugo theme that (among other things) lets users click a button to edit the relevant site page in Github. I build the edit URL in my template using the site’s provided repo name, the page Path, etc.

At the moment I check if there’s a language-specific subdirectory like this:

{{ else if .Site.Language.Lang }}
{{ $editURL = printf “%s/edit/master/content/%s/%s” gh_repo (.Site.Language.Lang) .Path }}

However, this is creating the wrong URL for one of my theme users, as their site is not Multilingual, but they do have a specified language (English) for content that is not in an en subdir:

defaultContentLanguage = “en”
defaultContentLanguageInSubdir = false

If I switch the check to “is this site Multilingual”, however:

{{ else if .Site.IsMultiLingual }}
{{ $editURL = printf “%s/edit/master/content/%s/%s” gh_repo (.Site.Language.Lang) .Path }}

…I create the wrong URL for one of my own sites, because it is not Multilingual but does have the content in an en subdir.

defaultContentLanguage = “en”
defaultContentLanguageInSubdir = true

Is there a nice Hugo way of checking in a template whether defaultContentLanguageInSubdir is true, given that it isn’t a parameter?

Thanks for any help!

I think you can check .Site.Params for defaultContentLanguageInSubdir.

1 Like

Hmm, I thought you could but it’s not actually getting a value, I think it’s because it’s not in the [params] section of my config. I’ll poke at it some more.

Also looking more closely it seems like what I need to check is contentDir but that has the same problem.