HUGO

Tag teaser or paginator problem

Hello,

my tags web page https://tekki-tipps.de/en/tags/ shows the number of blog posts with certain tags. No matter which tag is clicked, all tags (tag teasers) are displayed. The whole thing worked. However, as I’m still heavily tinkering with the site at the moment, I must have introduced a bug at some point that I’ve only just noticed.

The taxonomy/list.html template is the tags web page. Clicking on a tag calls up taxonomy/tag.html. The partial tagTeaser is then called in the template. tagTeaser.html looks like this:

{{ range .Paginator.Pages }}
{{ partial "articleTeaser.html" . }}
{{ end }}
{{ partial "paginator" . }}

I suspect the error is at the range with .Paginator.Pages. How can I fill the paginator with only the selected tag?

The online version of the website still uses Hugo version 0.85, locally I have version 0.87.0+extended darwin/amd64 with the same result.

Am grateful for any tips.
Frank

Please share your project repository. Thanks.

Thank you for taking care of the problem. I have sent you my project.

themes/tekki/layouts/partials/head.html

{{ $paginator := .Paginate (where .Site.RegularPages "Section" "blog") }}

https://gohugo.io/templates/pagination

For a given Page, it’s one of the options above. The .Paginator is static and cannot change once created.

Thank you. I overlooked the fact that there can only be one Paginator. Unfortunately, I have several possible uses for a paginator for my blog.

In the head I have added the Paginator because of the URL ./page/X and the Canonical Link. SEO - Google Note:
{{ $paginator := .Paginate (where .Site.RegularPages "Section" "blog") }}
{{ if .IsHome }}
{{ if eq $paginator.PageNumber 1 }}
<link rel="canonical" href="{{ .Permalink }}" />
{{ else }}
<link rel="canonical" href="{{ .Permalink }}page/{{ $paginator.PageNumber }}/" />
{{ end }}
{{ else }}
<link rel="canonical" href="{{ .Permalink }}" />
{{ end }}

When I display a particular tag, I also need a paginator for the tag’s teasers. After I removed both of them, everything works now. But the reason for multiple paginators remains.

The third paginator is for the homepage and is used for the blog teasers. Is there a way to rebuild the Paginator - as a module - and then use it as Paginator-1, Paginator-2 … etc.?

Instantiate pagination conditionally. For example:

layouts/_default/baseof.html

<head>
  ...
  ...
  
  {{ if .IsHome }}
    {{ .Paginate (where site.RegularPages "Type" "post") }}
  {{ else }}
    {{ .Paginate .Pages}}
  {{ end }}

  {{ with .Paginator }}
    {{ if eq .PageNumber 1 }}
      ...
    {{ else }}
      ...
    {{ end }}
  {{ end }}

  ...
  ...
</head>

layouts/_default/home.html

{{ range .Paginator.Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}

layouts/_default/list.html

{{ range .Paginator.Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}

Notice that I placed the paginator instantiation in layouts/_default/baseof.html, not in layouts/partials/head.html. As I understand it, partials are rendered in parallel, so there’s no way to be sure that the head partial will be rendered first.

Wow, this works with the blog teasers and the tag teasers. The prerequisite is that the following entry is made as the last entry in the head area of the baseof.html:

{{ $pagelink := .Permalink }}
{{ if .IsHome }}
{{ .Paginate (where .Site.RegularPages “Section” “blog”) }}
{{ else }}
{{ .Paginate .Pages}}
{{ end }}

If this is not done, the build process will tear up the head section and push everything that comes after the paginator into the body section. I haven’t got the Canonical link right yet, but I can solve that another way.

The blog teaser and tag teaser have the same source code:

{{ range .Paginator.Pages }}
{{ partial “articleTeaser.html” . }}
{{ end }}
{{ template “_internal/pagination.html” . }}

The problem at the moment is that the design is torn apart by the automatically created text "Pager 1 " in the body area. "Pager 1 " is displayed invisibly at the very top left and creates the white stripe between the green header and the menu bar. I can’t get to the automatically generated text via CSS either.

On a single page, "<nil> " is displayed in place of "Pager 1 ".

Can I somehow suppress the automatic text output “Pager 1” or “<nil>” myself?

Please share your project repository.

Thank you for taking care of the problem. I have sent you my project.

diff --git a/themes/tekki/layouts/_default/baseof.html b/themes/tekki/layouts/_default/baseof.html
index bebfa69..60c543f 100644
--- a/themes/tekki/layouts/_default/baseof.html
+++ b/themes/tekki/layouts/_default/baseof.html
@@ -81,9 +81,9 @@
 
     {{ $pagelink := .Permalink }}
     {{ if .IsHome }}
-      {{ .Paginate (where .Site.RegularPages "Section" "blog") }}
+      {{ $noop := .Paginate (where .Site.RegularPages "Section" "blog") }}
     {{ else }}
-      {{ .Paginate .Pages}}
+      {{ $noop := .Paginate .Pages }}
     {{ end }}
   </head>:= .Paginate .Pages }}
     {{ end }}
1 Like

Now it works completely. It is really very helpful that you can ask questions here when you don’t know what to do. Thank you very much for the competent answer.

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