Created
December 21, 2017 11:03
-
-
Save kdambekalns/1587f4d0babc646dfc0ac9b9edc147ee to your computer and use it in GitHub Desktop.
Provide link to "other language" only if it "exists"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prototype(Acme.AcmeCom:LanguageVariantFinder) < prototype(Neos.Fusion:RawArray) { | |
requestedLanguageCode = ${documentNode.context.targetDimensions.language} | |
otherLanguageCode = ${this.requestedLanguageCode == 'en' ? 'de' : 'en'} | |
otherLanguageLabel = ${this.otherLanguageCode == 'en' ? 'Englisch' : 'German'} | |
otherLanguageText = ${this.otherLanguageCode == 'en' ? 'Diese Seite ist auch verfügbar auf' : 'This page is also available in'} | |
nodeVariantsExist = ${Array.length(q(documentNode).find('main').find('[instanceof TYPO3.Neos:Content]').context({'dimensions': {'language': [this.otherLanguageCode]}, 'targetDimensions': {'language': this.otherLanguageCode}}).get()) > 0} | |
otherLanguageNode = ${this.nodeVariantsExist ? q(documentNode).context({'dimensions': {'language': [this.otherLanguageCode, this.requestedLanguageCode]}, 'targetDimensions': {'language': this.otherLanguageCode}}).get(0) : null} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prototype(Acme.AcmeCom:LanguageVariantLink) < prototype(Neos.Neos:Content) { | |
wrapInHeader = ${true} | |
languageVariantData = Acme.AcmeCom:LanguageVariantFinder | |
languageVariantCode = ${this.languageVariantData.otherLanguageCode} | |
languageVariantLabel = ${this.languageVariantData.otherLanguageLabel} | |
languageVariantText = ${this.languageVariantData.otherLanguageText} | |
languageVariantNode = ${this.languageVariantData.otherLanguageNode} | |
@context.languageVariantNode = ${this.languageVariantData.otherLanguageNode} | |
@cache { | |
entryIdentifier { | |
node = ${node.identifier} | |
documentNode = ${documentNode.identifier} | |
variant = ${languageVariantNode.identifier} | |
} | |
entryTags { | |
node = ${'Node_' + node.identifier} | |
documentNode = ${'Node_' + documentNode.identifier} | |
variant = ${'Node_' + languageVariantNode.identifier} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{namespace neos=Neos\Neos\ViewHelpers} | |
<f:if condition="{languageVariantNode}"> | |
<f:then> | |
<f:if condition="{wrapInHeader}"><header></f:if> | |
<nav role="navigation"> | |
{languageVariantText}: <neos:link.node node="{languageVariantNode}" additionalAttributes="{'rel': 'alternate', 'hreflang': '{languageVariantCode}'}">{languageVariantLabel}</neos:link.node> | |
</nav> | |
<f:if condition="{wrapInHeader}"></header></f:if> | |
</f:then> | |
<f:else> | |
<f:if condition="{neos:rendering.inBackend()}"> | |
<f:if condition="{wrapInHeader}"><header></f:if> | |
<nav role="navigation"> | |
This page has | |
<a rel="alternate" hreflang="zz">no translation available</a> <em>(this is only visible for editors)</em> | |
</nav> | |
<f:if condition="{wrapInHeader}"></header></f:if> | |
</f:if> | |
</f:else> | |
</f:if> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment