templates/seo/seo.html.twig line 1

Open in your IDE?
  1. {#-
  2.  # content array
  3.  # seo array
  4.  # shadowBaseLocale string
  5.  # localizations array
  6. -#}
  7. {% if localizations is not defined %}
  8.     {% deprecated 'The "urls" variable is deprecated, set "localizations" instead in the "seo.html.twig".' %}
  9.     {% set localizations = {} %}
  10.     {% for locale, url in urls %}
  11.         {% set localizations = localizations|merge({
  12.             (locale): {
  13.                 locale: locale,
  14.                 url: sulu_content_path(url, null, locale),
  15.             }
  16.         }) %}
  17.     {% endfor %}
  18. {% endif %}
  19. {#- merge seo data with _seo from attributes for custom urls -#}
  20. {% set seo = seo|default([])|merge(app.request.attributes.get('_seo', [])|default([])) %}
  21. {#- fallback to content title when no seo title is set -#}
  22. {# {{ dump(content)}} #}
  23. {% set seoTitle = seo.title|default(content.title|default()) %}
  24. {% if seo.title is defined and (seo.title is null or seo.title is empty) %}
  25.                     {% set brand_sm = 'Oakas Lane' %}
  26.                     {% set brand_lg = 'Oakas Lane' %}
  27.                     {# Page title of Previous directory #}
  28.                    
  29.                   {% set PageTitleOfPreDir = '' %}
  30.                       {% if content.title !='Homepage' %}
  31.                           {% set page = sulu_content_load_parent(uuid, {'title': 'title'}) %}
  32.                         {% if page.content.title !='Homepage' %}
  33.                             {% set PageTitleOfPreDir = page.content.title%}
  34.                         {% endif %}
  35.                     {% endif %}
  36.                     
  37.                     {% if seoTitle|length > 75 %}
  38.                         {% if PageTitleOfPreDir != '' %}
  39.                             {% set seoTitle =  seoTitle~' | '~PageTitleOfPreDir~' | '~brand_sm %}
  40.                         {% else %}    
  41.                             {% set seoTitle =  seoTitle~' | '~brand_sm %}
  42.                         {% endif %}
  43.                     {% else %}
  44.                         {% if PageTitleOfPreDir != '' %}
  45.                             {% set seoTitle =  seoTitle~' | '~PageTitleOfPreDir~' | '~brand_lg %}
  46.                         {% else %}    
  47.                             {% set seoTitle =  seoTitle~' | '~brand_lg %}
  48.                         {% endif %}
  49.                     {% endif %}
  50. {% endif %}
  51. {% set seoDescription = seo.description|default() %}
  52. {% if seo.description is defined and (seo.description is null or seo.description is empty) %}
  53.                     {% set discovor = 'Discover more'|trans  %}
  54.                     
  55.                     {% if  content.blocks[0].PageCoverShortDescription is defined  %}
  56.                          {% set seoDescription = content.blocks[0].PageCoverShortDescription %}
  57.                     {% endif %} 
  58.                  
  59.                     {% if seoDescription!='' %}
  60.                     {% if seoDescription|length < 160 %}
  61.                     {% set seoDescription = seoDescription~'. '~discovor  %}
  62.                     {% else %}
  63.                         {% set seoDescription = seoDescription|regex("/^.*?[.!?](?:\s|$)(?!.*\)/", " ")~'. '~ discovor %}
  64.                     {% endif %}
  65.                     {% endif %}
  66. {% endif %}
  67.  
  68. {% set seoKeywords = seo.keywords|default() %}
  69. {% set seoRobots = '' %}
  70. {%- if seo.noIndex|default(false) -%}
  71.     {% set seoRobots = seoRobots ~ 'noIndex' -%}
  72. {%- else -%}
  73.     {% set seoRobots = seoRobots ~ 'index' -%}
  74. {%- endif -%}
  75. {%- if seo.noFollow|default(false) -%}
  76.     {% set seoRobots = seoRobots ~ ',noFollow' -%}
  77. {%- else -%}
  78.     {% set seoRobots = seoRobots ~ ',follow' -%}
  79. {%- endif -%}
  80. {% set seoCanonical = seo.canonicalUrl|default() %}
  81. {%- if not seoCanonical and shadowBaseLocale and localizations[shadowBaseLocale]|default() %}
  82.     {% set seoCanonical = localizations[shadowBaseLocale].url %}
  83. {%- endif -%}
  84. {#- render blocks -#}
  85. {%- if   app.request.get('_route') == "sulu_search.website_search" -%}
  86.     {% if app.request.locale == 'en'%}
  87.         {% set seoTitle = 'Search Page | Oakas Lane' %}
  88.       {#   {% else %}
  89.         {% set seoTitle = 'Oakas Lane Search Page' %} #}
  90.     {% endif %}
  91.     {% if app.request.locale == 'de' %}
  92.         {% set seoTitle = 'Suchseite | Oakas Lane' %}
  93.     {% endif %}
  94.     {% if app.request.locale == 'fr' %}
  95.         {% set seoTitle = 'Page de recherche | Oakas Lane' %}
  96.     {% endif %}
  97. {%- endif -%}
  98. {%- block title -%}
  99.     {%- if seoTitle -%}
  100.         <title>{{ seoTitle }}</title>
  101.     {%- endif -%}
  102. {%- endblock -%}
  103. {%- block description -%}
  104.     {%- if seoDescription -%}
  105.         <meta name="description" content="{{ seoDescription }}"/>
  106.     {%- endif -%}
  107. {%- endblock -%}
  108. {%- block keywords -%}
  109.     {%- if seoKeywords -%}
  110.         <meta name="keywords" content="{{ seoKeywords }}"/>
  111.     {%- endif -%}
  112. {%- endblock -%}
  113. {%- block robots -%}
  114.     {%- if seoRobots -%}
  115.     {% if app.request.get('_route') != "sulu_search.website_search" %}
  116.         <meta name="robots" content="{{ seoRobots }}"/>
  117.         {% else %}
  118.         <meta name="robots" content="noindex,follow" />
  119.         {% endif %}
  120.     {%- endif -%}
  121. {%- endblock -%}
  122. {%- block urls -%}
  123.     {#- when only one language do not show alternative -#}
  124.     {%- if localizations|length > 1 -%}
  125.         {%- for localization in localizations -%}
  126.             {%- if localization.alternate is not defined or localization.alternate -%}
  127.                 {% if localization.locale !='fr' %}
  128.                          {% if app.request.get('_route') == "sulu_search.website_search" %}
  129.                             {# <link rel="alternate" href="{{ app.request.getSchemeAndHttpHost() }}{{ path('sulu_search.website_search' ,{'lang':localization.locale }) }}" hreflang="{{ localization.locale|replace({'_': '-'}) }}"/> #}
  130.                             <link rel="alternate" href="{{ app.request.getSchemeAndHttpHost() }}{{ path('sulu_search.website_search' ,{'lang':localization.locale }) }}" hreflang="x-default"/>
  131.                         {% else %}
  132.                             {# {% if request.defaultLocale == request.resourceLocatorPrefix|replace({'/': ''}) %}
  133.                                <link rel="alternate" href="{{ request.portalUrl }}" hreflang="x-default"/>
  134.                             {% else %} #}
  135.                                <link rel="alternate" href="{{ request.portalUrl }}" hreflang="{{ request.resourceLocatorPrefix|replace({'/': ''}) }}"/>
  136.                             {# {% endif %} #}
  137.                         {% endif %}
  138.                         
  139.                   {% endif %}
  140.             {%- endif -%}
  141.         {%- endfor -%}
  142.     {%- endif -%}
  143. {%- endblock -%}
  144. {%- block canonical -%}
  145.     {#- Set canonical to itself if a bot clone the page -#}
  146.      {% if app.request.get('_route') == "sulu_search.website_search"%}
  147.            <link rel="canonical" href="{{ app.request.getSchemeAndHttpHost() }}{{ path('sulu_search.website_search' ,{'lang':app.request.locale  }) }}"/>
  148.      {% else %}
  149.             <link rel="canonical" href="{{ seoCanonical|default(app.request.uri) }}"/>
  150.      {% endif %}
  151.    
  152. {%- endblock -%}