Getting section/subsection titles for multilingual site

Is there a more efficient way than the way I am doing below?

               {{ if eq .Language.Lang "en" }}
               {{- with site.GetPage "blog/foo/_index.md"}}
                <a href="{{ .Permalink }}">{{ .Title }}</a>
                {{- end }}
                {{ else }}
                {{- with site.GetPage "blog/foo/_index.fr.md"}}
                <a href="{{ .Permalink }}">{{ .Title }}</a>
                {{- end }}
                {{- end }}

I need to replicate this in different partials and templates for different sections, but the above code seems too verbose…

Get the permalink for the current section.

{{ with .CurrentSection }}
  {{ .Permalink }}
{{ end }}

Get the permalink for a specific section:

{{ with site.GetPage "/blog/foo/foo-2" }}
  {{ .Permalink }}
{{ end }}

When you configure your project with one language, there is one “site.”
When you configure your project with multiple languages, there is one “site” per language.

When you do something like .Site.GetPage (or site.GetPage to avoid context issues), it is already tied to a specific language (site).

I thought it was necessary to call _index.md when using .GetPage (wrong assumption). This makes everything way easier.

{{- with site.GetPage "/blog/foo/" }}
  <a href="{{ .Permalink }}">{{ .Title }}</a>
{{- end }}

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