diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 5dbdbadc2ab..314a6bf2288 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -17,16 +17,22 @@
{{ define "main" }}
{{ partial "docs-nav.html" . }}
- {{ $showSidebar := (gt (len ($.Scratch.Get "secondLevel").Sections) 0) }}
+ {{ $secondLevel := ($.Scratch.Get "secondLevel") }}
+ {{ $.Scratch.Set "showSidebar" false }}
+ {{ with $secondLevel }}
+ {{ if (gt (len .Sections) 0) }}
+ {{ $.Scratch.Set "showSidebar" true }}
+ {{end}}
+ {{end}}
- {{ if $showSidebar }}
+ {{ if ($.Scratch.Get "showSidebar") }}
{{end}}
-