Partials inside single.html not working

I am having difficulty using partials inside single.html. The partial works fine in my main index.html (home page) but not on single.html

my layouts/index.html works fine:

  {{ partial "header.html" .}}
  <h1>test title</h1>
  hello
</body>
</html>

my layouts/_default/single.html does not render the partial.

  {{ partial "header.html" .}}

  <h1>{{ .Title }}</h1>
  {{ .Content }}

</body>
</html>

The header.html:

<!DOCTYPE html>
<html>

<head>

    <link rel="stylesheet" type="text/css" href="{{ .Site.BaseURL }}css/style.css"/>
</head>
<body>
<div id="sidebar">
  {{ range first 5 .Data.Pages.ByDate }}
  <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
  {{ end }}
</div>

Not sure if you see an error message or not, or what you mean by “not working”, but I have created an issue to check that (see below).

But in general, it is important to understand that a Page in Hugo can be either a list page or a leaf page (leaf = no children).

So when you do a {{ range first 5 .Data.Pages.ByDate }} you get a list of the pages that is a child of that page. For the home page, this is all the pages, for a section, it is the pages in that section etc. For a regular content page, there aren’t any pages to show (no children).

Depending on what you want to show, this may be an option:

<div id="sidebar">
{{ if .IsPage }}
  {{ range first 5 .Site.Pages.ByDate }}
  <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
  {{ end }}
{{ else }}
 {{ range first 5 .Data.Pages.ByDate }}
  <h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
  {{ end }}
{{ end }}
</div>
```


https://github.com/spf13/hugo/issues/2947

Another solution. Try to create a template layouts/_default/section.html and copy the code of single.html.

Thanks Bep, You’re explanation with the child page helped. Your code example helped me understand the difference between Site and Data.