wiki-grav/plugins/langswitcher/templates/partials/langswitcher.hreflang.html.twig
2022-11-19 19:41:01 +01:00

17 lines
799 B
Twig

{% set language_obj = grav.language %}
{% for language in langswitcher.languages %}
{% if langswitcher.translated_routes[language] %}
{% set lang_url = langswitcher.translated_routes[language] ~ page.urlExtension %}
{% else %}
{% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
{% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
{% endif %}
{% set href_url = uri.base ~ lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query) %}
{% if (language_obj.default == language and config.languages.include_default_lang == false) %}
<link rel="alternate" hreflang="x-default" href="{{ href_url }}" />
{% endif %}
<link rel="alternate" hreflang="{{ language }}" href="{{ href_url }}" />
{% endfor %}