HUGO

[Fixed] Set an aria-current attribute on a multilingual menu seems buggy?

I’m on the last release 0.71, I’ve tried the last two.

Here is my config.toml

[languages]
  [languages.en]
    languageName ="English"
    Lang ="en"
    weight ="1"
    contentDir = "content/en"
  [[languages.en.menu.main]]
    identifier  = "welcome"
    name        = "Welcome"
    pre        = ""
    url         = "/"
    weight     = 1   
  [[languages.en.menu.main]]
    identifier  = "who"
    name        = "Who we are"
    pre        = ""
    url         = "/who-we-are/"
    weight     = 2   
  [[languages.en.menu.main]]
    identifier  = "what"
    name        = "What we do"
    pre        = ""
    url         = "/what-we-do/"
    weight     = 3  
  [[languages.en.menu.main]]
    identifier  = "how"
    name        = "How to Reach Us"
    pre        = ""
    url         = "/how-to-reach-us/"
    weight     = 4        
  [languages.fr]
    languageName ="Français"
    Lang ="fr"
    weight ="2"
    contentDir = "content/fr" 
  [[languages.fr.menu.main]]
    identifier  = "welcome"
    name        = "Bienvenue"
    pre        = ""
    url         = "/"
    weight     = 1     
  [[languages.fr.menu.main]]
    identifier  = "who"
    name        = "Qui nous sommes"
    pre        = ""
    url         = "/qui-nous-sommes/"
    weight     = 2   
  [[languages.fr.menu.main]]
    identifier  = "what"
    name        = "Ce que nous faisons"
    pre        = ""
    url         = "/ce-que-nous-faisons/"
    weight     = 3  
  [[languages.fr.menu.main]]
    identifier  = "how"
    name        = "Comment nous joindre"
    pre        = ""
    url         = "/comment-nous-joindre/"
    weight     = 4    

as well as the code to my menu

        <nav itemscope itemtype="http://schema.org/SiteNavigationElement" aria-label="main" role="navigation" class="nav-main">
          <ul>
            {{- $currentPage := . -}}
            {{ range .Site.Menus.main -}}
              {{ $isMenuCurrent := eq (.URL | relLangURL) $currentPage.RelPermalink }}
            <li {{ if $isMenuCurrent }} class="active" aria-current="true"{{ end }} >
                <a href="{{ .URL | absLangURL }}">{{ .Name }}</a>
            </li>
            {{- end }}
</ul>
    </nav>

and debugging

<li {{ if $isMenuCurrent }} class="active" aria-current="true"{{ end }} >
      <p style="color:red;">{{(.URL | relLangURL)}}</p>
      <p style="color:lime;">{{$currentPage.RelPermalink}}</p>  
      <a href="{{ .URL | absLangURL }}">{{ .Name }}</a>
    </li>

Thx,

Here is how I implemented it in the zen theme.

I see it works for you … I must be missing something in the config.toml

  <ul>
  {{ $currentPage := . -}}
{{ range .Site.Menus.main -}}
<li>
  <p style="color:red;"> $currentPage.IsMenuCurrent {{($currentPage.IsMenuCurrent "main" .)}}</p>
  <p style="color:lime;"> $currentPage.IsMenuCurrent {{($currentPage.IsMenuCurrent "main" .)}}</p>
  <a href="{{ .URL | relLangURL }}" {{ if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} class="active" aria-current="page"{{ end }}>{{ .Name }}</a></li>
{{ end -}}
</ul>

Fixed

Using Partial instead of PartialCached