Search code examples
typo3typoscripttypo3-8.x

How to include links to translations in HMENU sitemap?


I would like to create a sitemap via TypoScript which does also include links to all available translations. Unfortunately the special=language feature does only work for the current page, not for multiple pages. A combination of a regular HMENU with special=language menus in its items would be perfect.

My approach:

lib.menu = HMENU
lib.menu {
    entryLevel = 0
    1 = TMENU
    1{
        expAll = 1
        NO{
            doNotShowLink = 1
            allWrap{
                postCObject = COA
                postCObject{
                    stdWrap.wrap = <url>|</url>
                    1 = TEXT
                    1{
                        typolink.parameter.field=uid
                        typolink.returnLast = url
                        wrap = <loc>|</loc>
                    }

                    2 < .1
                    2.typolink.additionalParams = &L=1
                    2.wrap = <xhtml:link rel="alternate" hreflang="en" href="|" />
                }
            }
        }
    }
    2 < .1
    3 < .1
}

That almost works, but unfortunately links will also be generated for non-available translations.


Solution

  • You can check if the translated page is exists using the typoscript select query :

    2.if.isTrue.numRows {
        table = pages_language_overlay
        select {
            languageField = 0
            where = sys_language_uid = 1
            pidInList.field = uid
        }
    }
    

    Note: languageField is for selecting the language field, we need to disable in order to set sys_language_uid field in where clause. For disabling languageField we need to set languageField = 0. Check more information here.