I am still new to Hugo and kinda struggle with the GO syntax. I try to create an if condition based on the current active language. According to the Hugo docs I can use .Site.Language.LanguageName to get the current active language but somehow my if statement is ignored and the link is always shown.
{{ range .AllTranslations }}
{{ if eq .Site.Language.LanguageName "English" }}
<a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a>
{{ end }}
{{ end }}
What is wrong with this condition? (I guess it must be a Hugo newbie issue )
If I use {{ .Site.Language.LanguageName }} in my template for troubleshooting the active language is displayed correctly.
Thank you @bep for the example. Unfortunately your code doesn’t work either. I try to make a custom language switcher which has different code snippets depending on the language (Thai or English). So basically I try to create an if statement which will show a certain code only if the current active language is English and another code snipped if the language is Thai.
{{ range .AllTranslations }}
{{ if eq .Site.Language.LanguageName "English" }}
CODE FOR ENGLISH LANGUAGE
{{ else }}
CODE FOR THAI LANGUAGE
{{ end }}
{{ end }}
Any idea why my if conditions doesnt work?
{{ if eq .Site.Language.LanguageName "English" }}
Appreciate every help as I already have wasted more then an hour to get this simple thing working