templates/vitrine/lexend/components/pages/canonical.html.twig line 1

Open in your IDE?
  1. {% set available_locales = app_locales|split('|') %}
  2. {% if page is not empty %}
  3.     {% set current_locale = app.request.locale %}
  4.     {% set current_url = app.request.schemeAndHttpHost ~ app.request.basePath ~ app.request.pathInfo %}
  5.     {% set domain_urls = {} %}
  6.     {% for locale in available_locales %}
  7.         {% set locale_path = getPathPageHasLanguages(page.id, locale) %}
  8.         {% if locale_path %}
  9.             {% if locale == default_locale %}
  10.                 {% set locale_url = domain ~ locale_path %}
  11.             {% else %}
  12.                 {% set locale_url = domain ~ '/' ~ locale ~ locale_path %}
  13.             {% endif %}
  14.             {% if locale == current_locale %}
  15.                 {% set locale_url = current_url %}
  16.             {% endif %}
  17.             {% set domain_urls = domain_urls|merge({(locale): locale_url}) %}
  18.         {% endif %}
  19.     {% endfor %}
  20.     <link rel="canonical" href="{{ current_url }}" />
  21.     {% if domain_urls.en is defined %}
  22.         <link rel="alternate" hreflang="x-default" href="{{ domain_urls.en }}" />
  23.     {% endif %}
  24.     {% for locale in available_locales %}
  25.         {% if domain_urls[locale] is defined %}
  26.             <link rel="alternate" hreflang="{{ locale }}" href="{{ domain_urls[locale] }}" />
  27.         {% endif %}
  28.     {% endfor %}
  29. {% endif %}