Creating a combined page for two or more content types

I’m trying to work more on my indieweb support on my website. I want to start with POSSE and have a “notes” content type which will act as starting point for posting stuff to social media like twitter and mastodon. i created a new content type and that works and stuff. But now i want to make a page with combined both content types, posts and notes. I cant get it working. My first thought would be, creating a custom page with content/all/index.md and in the index.md i point it to a custom layout page, which would act as something like a new “index.html” homepage template. But hugo has a problem with pagination in that case and throws a error:

ERROR 2020/04/03 11:43:23 Failed to render pages: render of "page" failed: "/home/preuss/permanent/blog/themes/xsfx/layouts/_default/all.html:4:23": execute of template failed: template: _default/all.html:4:23: executing "main" at <$paginator.Pages>: error calling Pages: runtime error: invalid memory address or nil pointer dereference

and here is all.html:

{{ define "main" }}
  <main>
    {{ $paginator := .Paginate (where .Site.RegularPages "Type" "eq" "posts") }}
    {{ range $paginator.Pages }}
    <article class="h-entry">
      {{ partial "article.html" . }}
      <hr>
    </article>
    {{ end }}
    {{ partial "pagination.html" . }}
  </main>
{{ end }}

maybe im completly in the wrong direction and i should do it with taxonomy or something.

I can modify my index.html like this:

{{ define "main" }}
  <main>
    {{ $paginator := .Paginate (where .Site.RegularPages "Type" "in" (slice "posts" "notes")) }}
    {{ range $paginator.Pages }}
    <article class="h-entry">
      {{ partial "article.html" . }}
      <hr>
    </article>
    {{ end }}
    {{ partial "pagination.html" . }}
  </main>
{{ end }}

and it works fine… but i dont want it to be on index.html… i want this on all.html or /all/index.html.

Hi there,

Pagination is only available in a list context: https://gohugo.io/templates/pagination/#list-paginator-pages

Try renaming to content/all/_index.md instead.

1 Like

yes thats what i was looking for :smile: . this helps me already alot!!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.