Table of Contents
Multilingual Index
A small index page that groups every page on the site by language. Useful when you have a multilingual site and want a single landing point that fans out to each language's content.
Prerequisites
- Multilingual switched on, with per-language directory data declaring
langfor your content. The multilingual site tutorial walks through both. - Pages include
translationKeyin their front matter if you want sibling links. package.jsonwith"type": "module"and scripts (start,build).settings.urlset; usepathPrefixif you deploy under a subpath.
1) Create the index page
src/content/pages/languages-index.md:
---
title: 'Languages Index'
permalink: '/languages-index/'
layout: 'layouts/base.njk'
---
{% set t = collections.all | groupby("data.lang") %}
{% for lang, items in t %}
<p><strong>{{ settings.languages[lang].languageName }}</strong></p>
<ul>
{% for item in items %}
<li><a href="{{ item.page.url }}">{{ item.data.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
2) Verify
- Dev:
npm start - Build:
npm run build - Open the index page and confirm pages are grouped under each language.
Notes
- Content layout typically uses per-language folders (e.g.
src/content/en/,src/content/nl/) with a per-folder.11tydata.jssettinglang. collections.translationsMapis available when multilingual is on. Keys aretranslationKey; each entry holds the per-language metadata. Grouping bydata.langkeeps this example simple. Reach fortranslationsMapwhen you want sibling links.- To filter out drafts or
noindex, add a check inside the loop (e.g.{% if not item.data.draft and not item.data.noindex %}). - Honour
pathPrefixin permalinks when deploying under a subpath.
See also
Previous: Image Transform