Back to top Back to top
Light Dark

description

Create hreflang tags in TYPO3 with FLUID

page.headerData.500 = FLUIDTEMPLATE
page.headerData.500 {
    file = fileadmin/HrefLang.html // or EXT:ext_name/PathToTemplate
    dataProcessing {
        10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
        10 {
            special = language
            special.value = 0,1,3,4,5,6,7
            addQueryString = 1
            addQueryString {
                exclude = id, L, cHash
                method = GET
            }
            as = language
        }
    }
}

TYPO3 Fluid Template

<html
  xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
  data-namespace-typo3-fluid="true"
>
  {f:variable(name: 'hreflang', value: 'ch-de')}
  <f:spaceless>
    <f:for each="{language}" as="langItem">
      <f:switch expression="{langItem.languageUid}">
        <f:case value="1"
          >{f:variable(name: 'hreflang', value: 'ch-it')}</f:case
        >
        <f:case value="2"
          >{f:variable(name: 'hreflang', value: 'ch-fr')}</f:case
        >
        <f:case value="3"
          >{f:variable(name: 'hreflang', value: 'at-de')}</f:case
        >
        <f:case value="4"
          >{f:variable(name: 'hreflang', value: 'de-de')}</f:case
        >
        <f:case value="5"
          >{f:variable(name: 'hreflang', value: 'eu-en')}</f:case
        >
        <f:case value="6"
          >{f:variable(name: 'hreflang', value: 'fr-fr')}</f:case
        >
        <f:case value="7"
          >{f:variable(name: 'hreflang', value: 'it-it')}</f:case
        >
        <f:defaultCase
          >{f:variable(name: 'hreflang', value: 'ch-de')}</f:defaultCase
        >
      </f:switch>
      <f:if condition="{langItem.available}">
        <link rel="alternate" hreflang="{hreflang}" href="{langItem.link}" />
      </f:if>
      <f:if condition="{langItem.active}">
        <link rel="alternate" hreflang="x-default" href="{langItem.link}" />
      </f:if>
    </f:for>
  </f:spaceless>
</html>