We all know there’s a TYPO3.Neos:DimensionsMenu
TS object with which you can build a language menu.
But sometimes you need more flexibility and be able to create links to nodes in different content dimensions, e.g. in different language.
Here’s a trick to do it:
TYPO3.Neos:NodeUri {
node = ${q(documentNode).context({targetDimensions: {language: 'en'}, dimensions: {language: ['en']}}).get(0)}
}
Here’s a slightly more advanced example. I use it to add links inside article body to inform user that this article exists in alternative language. We only have Russian and English versions, so these are hard coded in the example, but you get the point. If this exact article doesn’t exist in alternative language dimension nothing is shown.
languageMenu = TYPO3.TypoScript:Tag {
lang = ${Array.first(node.context.dimensions.language)}
@context.altLang = ${this.lang == 'ru' ? 'en' : 'ru'}
tagName = 'a'
@context.altNode = ${q(documentNode).context({targetDimensions: {language: altLang}, dimensions: {language: [altLang]}})}
@if.nodeExists = ${altNode.count() > 0}
attributes.href = TYPO3.Neos:NodeUri {
node = ${altNode.get(0)}
}
content = ${altLang == 'en' ? 'Read this in English' : 'Читать по-русски'}
}