PaginatePath, home, and list templates

#1

I’m trying to understand the interactions of home and list templates with a custom value for PaginatePath.

In my config.yaml, I have “PaginatePath: archive”, with the understanding that my list pages would all be at /archive/2/index.html, /archive/3/index.html, etc.

In my theme’s layout/index.html I have:

<h3>Recent posts:</h3>
<ul>
{{- range first 5 .Data.Pages.ByDate.Reverse -}}
<li><time>{{ .Date.Format "2006-01-02" }}</time> - <a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{- end -}}
</ul>

to get the five most recent posts.

In my theme’s layout/_default/list.html, I have:

<ul>
{{ range .Paginator.Pages.ByDate.Reverse }}
<li>{{.Date.Format "2006-01-02"}} - <a href="{{.Permalink}}">{{.Title}}</a></li>
{{ end }}
</ul>
{{- if gt .Paginator.TotalPages 1 }}
{{ template "_internal/pagination.html" . }}
{{- end }}

to display all my content.

But when I generate the site, /archive/2/index.html is showing only five posts, and is also using layout/index.html to render the page, rather than list.html.

What might I be doing wrong?

1 Like
#2

I haven’t yet played with PaginatePath, and can look at that stuff later today. In the meanwhile, can you edit the code blocks so that they format and show as they need to:

```
my-code
```

Wrap the code in triple-backquotes.

#3

That is expected. The paginated pages always use index.html (not list.html) layout at least based on my experience.

Keep your pagination template only in the index.html.

#4

Thanks, that’s what I needed.

#5

@kaushalmodi thanks. Your bare-min theme is instructive, but I’m still struggling with getting Hugo to do what I want.

Ideally, what I’d like is some heading content on the home page of my site, followed by a list of 10 links to recent posts. Then /archive/2/index.html would pick up at post number 11, and show 50 links; /archive/3/index.html would show 50 links, etc.

When I try this in index.html:

{{- partial "header.html" . -}}
{{- if .IsHome -}}
{{- partialCached "home.html" . -}}
{{- end -}}
<ul>
{{- range .Paginator.Pages -}}
<li><time>{{ .Date.Format "2006-01-02" }}</time> - <a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{- end -}}
</ul>

The contents of the home.html partial show on all pages, not just the home page.

Additionally, all attempts to change the number of items to list on the home page causes a gap in the subsequent /archive/ pages: if I limit it to 10 items on /index.html, then /archive/2/index.html starts at item 50 (due to Paginate: 50 in my config.yaml). Or, if I goof with the range, pagination simply doesn’t get generated.

The documentation for the home page template and the .IsHome functions seem not to correspond with what I’m actually experiencing.

#6

The content would go in your content/_index.md file, and you show that using .Content in index.html layout file.

I’m not sure if we can do that. May be someone else can chime in for that.

I have not used .IsHome, but I would think that it was return true for home page and all paginated pages too. If you look in top-left of this page (page 2), it says that the .Kind is home.

In the same index.html layout file that I shared earlier, I do something like that using {{ if (eq 1 $paginator.PageNumber) }}.

Sorry, I don’t use that variable either. I just set it explicitly to 10 in the .Paginate call: {{ $paginator := .Paginate (.Pages.ByLastmod.Reverse) 10 }}doc.

The documentation says:

IsHome
true in the context of the homepage.

which seems to be true… as you see in the above example, the Kind is home for the “home page” and all the paginated pages too… and so IsHome is true too.


Update: Fix typo… I meant to type Kind but typed Type instead.

#7

Perhaps it’s due to how my content is arranged. I have all my Markdown files in /content, such that all generated pages are top-level links. I read the .IsHome documentation to indicate that Hugo knows the difference between the site’s home page (/index.html) and everything else, but maybe that only means “everything that isn’t a top-level page” (which is still inaccurate, to my mind, but not much I can do about that).

Thanks again for the help!

#8

Hugo distinguishes among 5 Page Kinds. See this for more info:

It’s probably just that the home page (paginated or not) is still of home Kind, and so IsHome is true for those.

I don’t understand how that is related to this pagination question. Also that style of organization is completely normal.

You’re welcome :slight_smile: