First steps with Hugo …
I’d like to add a link to my page footer (i.e., into a template) which points to a static page within my Hugo site, depending on the language of the current page.
I’m setting up a multilanguage site (EN/DE), and in the site’s footer, I want to add a link which is called “Impressum” and points to /impressum if the language of the current page is DE, and is called “Imprint” and points to /en/imprint if the language of the current page is EN.
I’d appreciate any pointer to how I can achieve this.
Try <a href="{{ .LanguagePrefix }}/impressum">Impressum</a>
.
Reference:
What if the slug is also language-dependent? I currently have
/de/impressum and /en/legal-notice … My source files are called
impressum.de.md and impressum.en.md, though.
This should work:
{{ $siteLanguages := .Site.Languages }}
{{ $page := .Site.GetPage "/impressum" }}
{{ $pageLang := $page.Lang }}
{{ range $page.AllTranslations }}
{{ $translation := . }}
{{ range $siteLanguages }}
{{ if eq $translation.Lang .Lang }}
{{ if eq $pageLang .Lang }}
<span id="address" class="post-footer-item">
<a href="{{ $translation.URL }}" class="">{{ i18n "impressumTitle" }}</a>
</span>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
2 Likes
Perfect, works like a charm 
Thanks so much!
1 Like