templates/bundles/SuluWebsiteBundle/Extension/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. {% set seoTitle = seo.title|default(content.title|default()) %}
  23. {% set seoDescription = seo.description|default() %}
  24. {% set seoKeywords = seo.keywords|default() %}
  25. {% set seoRobots = '' %}
  26. {%- if seo.noIndex|default(false) -%}
  27.     {% set seoRobots = seoRobots ~ 'noIndex' -%}
  28. {%- else -%}
  29.     {% set seoRobots = seoRobots ~ 'index' -%}
  30. {%- endif -%}
  31. {%- if seo.noFollow|default(false) -%}
  32.     {% set seoRobots = seoRobots ~ ',noFollow' -%}
  33. {%- else -%}
  34.     {% set seoRobots = seoRobots ~ ',follow' -%}
  35. {%- endif -%}
  36. {% set seoCanonical = seo.canonicalUrl|default() %}
  37. {%- if not seoCanonical and shadowBaseLocale and localizations[shadowBaseLocale]|default() %}
  38.     {% set seoCanonical = localizations[shadowBaseLocale].url %}
  39. {%- endif -%}
  40. {#- render blocks -#}
  41. {%- block title -%}
  42.     {%- if seoTitle -%}
  43.         <title>{{ seoTitle }}</title>
  44.         <meta property="og:title" content="{{ seoTitle }}" />
  45.         <meta name="twitter:title" content="{{ seoTitle }}">
  46.     {%- endif -%}
  47. {%- endblock -%}
  48. {%- block description -%}
  49.     {%- if seoDescription -%}
  50.         <meta name="description" content="{{ seoDescription }}"/>
  51.         <meta property="og:description" content="{{ seoDescription }}" />
  52.         <meta name="twitter:description" content="{{ seoDescription }}">
  53.     {%- endif -%}
  54. {%- endblock -%}
  55. {%- block keywords -%}
  56.     {%- if seoKeywords -%}
  57.         <meta name="keywords" content="{{ seoKeywords }}"/>
  58.     {%- endif -%}
  59. {%- endblock -%}
  60. {%- block robots -%}
  61.     {%- if seoRobots -%}
  62.         <meta name="robots" content="{{ seoRobots }}"/>
  63.     {%- endif -%}
  64. {%- endblock -%}
  65. {%- block urls -%}
  66.     {#- when only one language do not show alternative -#}
  67.     {%- if localizations|length > 1 -%}
  68.         {%- for localization in localizations -%}
  69.             {%- if localization.alternate is not defined or localization.alternate -%}
  70.                 <link rel="alternate" href="{{ localization.url }}" hreflang="{{ localization.locale|replace({'_': '-'}) }}"/>
  71.             {%- endif -%}
  72.         {%- endfor -%}
  73.     {%- endif -%}
  74. {%- endblock -%}
  75. {%- block canonical -%}
  76.     {#- Set canonical to itself if a bot clone the page -#}
  77.     <link rel="canonical" href="{{ seoCanonical|default(app.request.uri) }}"/>
  78.     <meta property="og:url" content="{{ seoCanonical|default(app.request.uri) }}" />
  79. {%- endblock -%}
  80. {%- block type -%}
  81.     <meta property="og:type" content="website" />
  82. {%- endblock -%}
  83. {%- block image -%}
  84.     {%- if content -%}
  85. {#    {% set ogImage = og_image(content) %}#}
  86.         {% set ogImage = og_image({'content': content, 'image': open_graph.image}) %}
  87.         <meta property="og:image" content="{{ absolute_url(ogImage) }}" />
  88.         <meta name="twitter:image" content="{{ absolute_url(ogImage) }}">
  89.     {%- endif -%}
  90. {%- endblock -%}