I'm new to Lektor and I've been using this snippet in my layout to dynamically generate menus
{% for content in site.get('/').children %}
<li><a href="{{ content|url(alt=alt) }}">{{ content.title }}</a></li>
{% endfor %}
It works fine to produce the alt
url accordingly to the alternative (language) selected, but the title
is still shown only in the primary language of the content instead of the translated one.
That means that when a say french alt
is selected (and present in the url), menus are still i.e. Main
, Contact
instead of the french translated version.
I know I can work around this using a databag to hold a language mapping for the menus, but that would require to duplicate the title information in the databag and then make sure it stays in sync with whatever is in content.title
.
Ideally what I'm missing is a filter for title
where you can specify the alt
you want to use, or some other method that I'm not aware of?
Naive as it may be, I didn't realize that you can pass the alt
parameter in site.get
until after I looked at the source code. So the way to get the defined child pages for a certain language is:
{% for content in site.get('/', alt=alt).children %}
<li><a href="{{ content }}">{{ content.title }}</a></li>
{% endfor %}
And since we already specified the alt
parameter in the get, we don't need to filter the url
anymore for the current alt.