langswitcher.hreflang.html.twig 799 B

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