IsMenuCurrent not working using code from docs

I’m running Hugo v0.18.1 BuildDate: 2016-12-29T17:12:41Z

When I tried to use the code in the documentation to show an active class, it didn’t return any value. Has anyone had the same problem?

What could I be missing?

        <ul class="sidebar-menu">
          {{ $currentPage := . }}
          {{ range .Site.Menus.main }}
			<a class="sidebar-nav-item {{ if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} active{{end}}" href="{{.URL}}">{{ .Name }}</a>
          {{end}}
        </ul>

config.toml

[menu]
	[[menu.main]]
		name = "About"
		url = "/about/"
		weight = 1
		post = "This is more than meets the eye"

	[[menu.main]]
		name = "The Stories"
		url = "/categories/"
		weight = 2
		post = "Come sit by the table, have a drink and read a tale"

	[[menu.main]]
		name = "The Author"
		url = "/about/me/"
		weight = 3
		post = "Bruno Amaral"

	[[menu.main]]
		name = "Contact"
		url = "/contact/"
		weight = 4
		post = "Don't be shy, reach out"

You mean the very latest revision to the documentation?

Menus - Rendering nested menus

What template is your code snippet taken from? index.html? A partial?

If it’s from a partial, have you passed the context through to the partial?

<!-- Right: -->
{{ partial "nav.html" . }}
                      ^
<!-- Wrong: -->
{{ partial "nav.html" }}

I did use the dot to pass the context and am using this version of the code: https://gohugo.io/extras/menus/#section-menu-for-the-lazy-blogger

Ok, can you zip up your site and upload a copy somewhere? Will need to see that to debug this effectively.

there really isn’t much more to it.

This is the index:

{{ $loop := (.Paginate (where .Data.Pages "Type" "post") 1).Pages }}

{{ partial "header.html" . }}
	<body>

		<!-- Wrapper -->
			<div id="wrapper">

				{{ partial "top_navigation.html" . }}

				<!-- Main -->
					<div id="main">
						{{ partial "title_section.html" .}}


						{{ partial "highlighted_stories.html" . }}
						{{ range $loop }}
								{{ .Render "li" }}
							{{ end }}

						{{ partial "pagination.html" . }}
					</div>

			</div>

			{{ partial "footer-links.html" . }}

{{ partial "footer.html" . }}

top_navigation partial:

{{ $currentPage := . }}
				<!-- Header -->
					<header id="header">
						<h1><a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a></h1>
						<nav class="links">
							<ul>
							{{ range .Site.Menus.main }}
								<li><a href="{{ .URL }}"{{if or ($currentPage.IsMenuCurrent "main" . ) ($currentPage.HasMenuCurrent "main" . ) }} class="active"{{end}}>{{ .Name }}</a></li>
							{{ end }}
							</ul>
						</nav>

						<nav class="main">
							<ul>
								<li class="search">
									<a class="fa-search" href="#search">Search</a>
								</li>
								<li class="menu">
									<a class="fa-bars" href="#menu">Menu</a>
								</li>
							</ul>
						</nav>
					</header>

					<!-- Menu -->
						<section id="menu">
						<h2 class="sr-only">Index</h2>
							<!-- Links -->
								<section>
									<ul class="links">

									{{ range .Site.Menus.main }}
									<li>
										<a href="{{ .URL }}" {{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} class="active"{{end}}>
											<h3>{{ .Name }}</h3>
											<p>{{ .Post }}</p>
										</a>
									</li>
									{{ end }}

									</ul>
								</section>

						</section>

Hello! I have the same problem.

My index.html

{{ partial "header" . }}

partials/header.html

{{ $currentPage := . }}
{{ if .IsHome }}	
{{ range .Site.Menus.main }}
					<li class="{{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }}active{{ end }}">
						<a class="{{ .Pre }}" target="{{ .Post }}" href="{{ .URL | relLangURL }}">{{ .Name }}</a>
					</li>
{{ end }}
{{ else }}
{{ range .Site.Menus.main }}
					<li class="{{ if $currentPage.IsMenuCurrent "main" . }}active{{ end }}">
						<a target="{{ .Post }}" href="{{ .URL | relLangURL }}">{{ .Name }}</a>
					</li>
{{ end }}
{{ end }}

config.toml

[[menu.main]]
    name = "Home"
    url = "/#home"
    weight = 1
	pre = "js_anchor_link"
	post = ""

[[menu.main]]
    name = "CDN"
    url = "/cdn/"
    weight = 2
	pre = ""
	post = ""

[[menu.main]]
    name = "Hosting"
    url = "https://g-host-lab.com/"
    weight = 3
	pre = ""
	post = "_blank"	

[[menu.main]]
    name = "Network"
    url = "/#network"
    weight = 5
	pre = "js_anchor_link"
	post = ""	

[[menu.main]]
    name = "Why G-Core"
    url = "/#company"
    weight = 4  
	pre = "js_anchor_link"
	post = ""	

[[menu.main]]
    name = "Vacancy"
    url = "/careers/"
    weight = 6
	pre = ""
	post = ""	
	
[[menu.main]]
    name = "Contact US"
    url = "/#contact"
    weight = 7  
	pre = "js_anchor_link"
	post = ""

[[languages.ru.menu.main]]
    name = "Главная"
    url = "/#home"
    weight = 1	
	pre = "js_anchor_link"
	post = ""	

[[languages.ru.menu.main]]
    name = "CDN"
    url = "/cdn/"
    weight = 2	
	pre = ""
	post = ""	

[[languages.ru.menu.main]]
    name = "Хостинг"
    url = "https://g-host-lab.com/"
    weight = 3	
	pre = ""
	post = "_blank"	

[[languages.ru.menu.main]]
    name = "Компания"
    url = "/#company"
    weight = 4	
	pre = "js_anchor_link"
	post = ""	

[[languages.ru.menu.main]]
    name = "Покрытие"
    url = "/#network"
    weight = 5	
	pre = "js_anchor_link"
	post = ""
	
[[languages.ru.menu.main]]
    name = "Вакансии"
    url = "/careers/"
    weight = 6
	pre = ""
	post = ""
	
[[languages.ru.menu.main]]
    name = "Контакты"
    url = "/#contact"   
    weight = 7	
	pre = "js_anchor_link"
	post = ""	

The class “active” is not show on page http://site.ru/cdn/