langswitcher-logic.html.twig 1.5 KB

1234567891011121314151617181920212223242526272829
  1. {{ block('language_block_start') }}
  2. {% set display_format = display_format ?? config.get('plugins.langswitcher.language_display', 'long') %}
  3. {% for language in langswitcher.languages %}
  4. {% set active_class = '' %}
  5. {% set show_language = true %}
  6. {% if language == langswitcher.current %}
  7. {% set active_class = 'active' %}
  8. {% endif %}
  9. {% if langswitcher.translated_routes[language] %}
  10. {% set lang_url = langswitcher.translated_routes[language] ~ page.urlExtension %}
  11. {% else %}
  12. {% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
  13. {% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
  14. {% endif %}
  15. {% set untranslated_pages_behavior = grav.config.plugins.langswitcher.untranslated_pages_behavior %}
  16. {% if untranslated_pages_behavior != 'none' %}
  17. {% set translated_page = langswitcher.translated_pages[language] %}
  18. {% if (not translated_page) or (not translated_page.published) %}
  19. {% if untranslated_pages_behavior == 'redirect' %}
  20. {% set lang_url = url('/') %}
  21. {% elseif untranslated_pages_behavior == 'hide' %}
  22. {% set show_language = false %}
  23. {% endif %}
  24. {% endif %}
  25. {% endif %}
  26. {{ block('language_item') }}
  27. {% endfor %}
  28. {{ block('language_block_end') }}