Language switching within context
This commit is contained in:
parent
63fd774730
commit
5a1580c4d5
2 changed files with 7 additions and 3 deletions
|
@ -1,3 +1,3 @@
|
|||
{% for lang in languages %}
|
||||
<a{% if lang.code == currentlangcode %} class="active"{% endif %} href="/{{ lang.code }}">{{ lang.title }}</a>
|
||||
<a{% if lang.code == currentlangcode %} class="active"{% endif %} href="{{ lang.url }}">{{ lang.title }}</a>
|
||||
{% endfor %}
|
||||
|
|
|
@ -7,8 +7,12 @@ register = template.Library()
|
|||
# Language switcher
|
||||
@register.inclusion_tag('tags/language.html', takes_context=True)
|
||||
def language_switcher(context):
|
||||
url = context['page'].url
|
||||
return {
|
||||
'languages': [ { 'code': 'de', 'title': 'De' }, { 'code': 'fr', 'title': 'Fr' } ],
|
||||
'languages': [
|
||||
{ 'code': 'de', 'title': 'De', 'url': url.replace('/fr/','/de/') },
|
||||
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('/de/','/fr/') }
|
||||
],
|
||||
'currentlangcode': translation.get_language(),
|
||||
'request': context['request'],
|
||||
}
|
||||
|
@ -59,4 +63,4 @@ def footer_menu(context, parent, calling_page=None):
|
|||
'calling_page': calling_page,
|
||||
'menuitems': menuitems_children(parent),
|
||||
'request': context['request'],
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue