Neos 9.0.8 language switcher failes

I have in file DistributionPackages/Custom.Site/Configuration/Settings.CR.yaml

Neos:
  Neos:
    sites:
      '*':
        contentDimensions:
          # the defaultDimensionSpacePoint is used when resolving the "/" URL.
          defaultDimensionSpacePoint:
            language: en_US
          resolver:
            factoryClassName: Neos\Neos\FrontendRouting\DimensionResolution\Resolver\UriPathResolverFactory
            options:
              segments:
                - dimensionIdentifier: language
                  dimensionValueMapping:
                    # dimension value -> URL path segment
                    en_US: en
                    de: de
  ContentRepositoryRegistry:
    contentRepositories:
      default:
        contentDimensions:
          language:
            label: 'Language'
            icon: language
            values:
              'en_US':
                label: English (US)
              'de':
                label: Deutsch

I need a language switcher, but I cannot get dynamic values for vars: currentLanguage and languages in DistributionPackages/Custom.Site/Resources/Private/Fusion/Component/Template/Header/Header.fusion

prototype(Custom.Site:Component.Template.Header) < prototype(Neos.Fusion:Component) {

   currentLanguage = ‘’
   languages = ‘’

   renderer = afx`
      <nav id="mainNavbar" class="navbar navbar-expand-lg navbar-dark fixed-top navbar-transparent"> 	  
      <!-- Right-aligned Language Dropdown -->
          <ul class="navbar-nav ms-auto">
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">EN</a>
              <ul class="dropdown-menu dropdown-menu-dark">
                <li><a class="dropdown-item active" href="/">EN</a></li>
                <li><a class="dropdown-item" href="/de">DE</a></li>
              </ul>
            </li>
          </ul>
       </nav>
   `
}

I tried currentLanguage = ${Neos.Dimension.currentValue(site, ‘language’)}, languages = ${Neos.Dimension.allDimensionValues(site, ‘language’)}. But still vars were empty.

Hi can you please show the var_dump output of those helpers and just to be safe the site node as well so we can see what is its real $dimensionSpacePoint.

For debugging there is either Neos.Fusion:Debug or just write or hack an EEL helper to do \Neos\Flow\var_dump($value); die();

i am trying

prototype(Custom.Site:Component.Template.Header) < prototype(Neos.Fusion:Component) {

menu = ‘’

# All languages

languages = Neos.Neos:DimensionsMenuItems {

node = ${site}  # site node works

dimension = 'language'

}

# Current language from site

currentLanguage = ${site.activeDimensions.language[0].value}

But my currentLanguage always null.

(2) [{…}, {…}]

  1. 0:

    1. label: “English”

    2. node: {contentRepositoryId: ‘default’, workspaceName: ‘live’, dimensionSpacePoint: {…}, aggregateId: ‘d964e413-490a-4fdb-8d9d-370892376109’, originDimensionSpacePoint: {…}, …}

    3. state: null

    4. targetDimensions: {language: {…}}

    5. uri: “/”

    6. [[Prototype]]: Object

  2. 1:

    1. label: “Deutsch”

    2. node: {contentRepositoryId: ‘default’, workspaceName: ‘live’, dimensionSpacePoint: {…}, aggregateId: ‘d964e413-490a-4fdb-8d9d-370892376109’, originDimensionSpacePoint: {…}, …}

    3. state: null

    4. targetDimensions: {language: {…}}

    5. uri: “/de/”

Is not Neos 9.0 code but only for Neos <= 8.

As you wrote above this is correct - given you have the dimension language.

currentLanguage = ${Neos.Dimension.currentValue(site, ‘language’)

What does this helper return? If its not the desired output could you please show us the value of site.dimensionSpacePoint and site.originDimensionSpacePoint

2 Likes

Hallo Marc,

I changed prototype(Custom.Site:Component.Template.Header) < prototype(Neos.Fusion:Component) {
to prototype(Custom.Site:Content.Menu) < prototype(Neos.Neos:ContentComponent) {
and wrote as you mentioned currentLanguage = ${Neos.Dimension.currentValue(site, 'language')}and now instead null I get what I need

currentLanguage:

  1. {value: ‘en_US’, specializationDepth: 0, constraints: {…}, configuration: {…}}

    1. configuration: {label: ‘English’}

    2. constraints: {}

    3. specializationDepth: 0

    4. value: “en_US”

    5. [[Prototype]]: Object

Thank you.

you are probably interested in .value, so

currentLanguage = ${Neos.Dimension.currentValue(site, ‘language’).value

(I forgot that this is a value object returned :O)