0

我是 Lektor 的新手,我一直在我的布局中使用这个片段来动态生成菜单

{% for content in site.get('/').children %}
    <li><a href="{{ content|url(alt=alt) }}">{{ content.title }}</a></li>
{% endfor %}

alt根据所选的替代(语言)生成 url 可以正常工作,但title仍然仅以内容的主要语言而不是翻译的语言显示。

That means that when a say french altis selected (and present in the url), menus are still ie Main, Contactinstead of the french translated version.

我知道我可以使用数据包来保存菜单的语言映射来解决这个问题,但这需要复制数据包中的标题信息,然后确保它与content.title.

理想情况下,我缺少的是一个过滤器title,您可以在其中指定alt要使用的过滤器,或者我不知道的其他方法?

4

1 回答 1

0

尽管可能很天真,但直到我查看源代码后,我才意识到您可以传递alt参数。site.get所以获取特定语言的已定义子页面的方法是:

{% for content in site.get('/', alt=alt).children %}
    <li><a href="{{ content }}">{{ content.title }}</a></li>
{% endfor %}

并且由于我们已经alt在 get 中指定了参数,因此我们不再需要url为当前的 alt 过滤。

于 2018-09-10T05:43:22.840 回答