Hugo 0.140 and pagination is broken

After updating Hugo to new version from the old one, I get this error while building the site

execute of template failed: template: partials/head.html:29:21: executing "partials/head.html" at <.Paginate>: error calling Paginate: pagination not supported for this page: kind: "page

The code in line 29 is {{- $paginator = .Paginate .RegularPages -}}

my pagination code which worked on far older Hugo version:

    {{ $paginator := . }}
    {{- if .IsHome -}}
    {{- $paginator = .Paginate (after 1 (where .Site.RegularPages "Section" "posts")) -}}
    {{- else if eq .Section "advice" -}}
    {{- $theTerm := .Params.tags }}
    {{- $pages := where site.RegularPages "Type" "posts" }}
    {{- $relatedposts := $pages.RelatedTo (keyVals "tags" $theTerm) }}
    {{- $paginator = .Paginate $relatedposts -}}
    {{ else }}
    {{- $paginator = .Paginate .RegularPages -}}
    {{- end }}

It may have done what you want, but it didn’t work; its failures were silent. You cannot invoke pagination when the page kind is page. You can only invoke pagination from home, section, taxonomy, and term templates.

Wrap your code with a conditional:

{{- if in (slice "home" "section" "taxonomy" "term") .Kind }}
  {{ $paginator := . }}
  {{- if .IsHome -}}
    {{- $paginator = .Paginate (after 1 (where .Site.RegularPages "Section" "posts")) -}}
  {{- else if eq .Section "advice" -}}
    {{- $theTerm := .Params.tags }}
    {{- $pages := where site.RegularPages "Type" "posts" }}
    {{- $relatedposts := $pages.RelatedTo (keyVals "tags" $theTerm) }}
    {{- $paginator = .Paginate $relatedposts -}}
  {{ else }}
    {{- $paginator = .Paginate .RegularPages -}}
  {{- end }}
{{- end }}

above code seems to work, but other error came up. Newer Hugo seem to brake this code too:
{{ $.Site.Params.images | absURL }}

in the google schema line:

"image": {{ if .Params.image }}{{ .Params.image | absURL }}{{ else}}{{ $.Site.Params.images | absURL }}{{ end }},

error:
unable to cast []interface to string

Without looking at your site, I’m guessing that the params.images key in your site configuration is an array, and your can’t convert an array to a URL.

It worked earlier, now it fetches the value but error came up. Live website is running without problems on older version of hugo. Current one with errors of new hugo is not published.

Like I said, without access to your site I’m just guessing, which isn’t a great use of your time, or mine.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

This looks familiar to an issue I ran into recently that is based on “old code”.

Change from

{{ else }}
{{- $paginator = .Paginate .RegularPages -}}
{{- end }}

to

{{ else }}
{{- end }}

and see if the error goes away (pretty sure) and any pagination goes missing (pretty sure too).

I had the same issue a number of Hugo versions back and ended up finding, that there is no pagination available on single pages (true) which Hugo until that version just silently ignored in that last condition, but since that version complained loudly about.

Depending on the structure of your website (which you did not say anything about) anytime Hugo goes into the last three lines of the else an error is thrown. Don’t use else.

A pagination exists only on home and list pages, not on single pages…

From the looks of it you need another condition that checks for isNode and then creates the default pagination.

The pagination issue was resolved in my initial reply.

You should not check IsNode because that returns true for 404 templates:
https://github.com/gohugoio/hugo/issues/12162

Instead, as shown above, check if the page kind is one of home, section, taxonomy, or term.

The OP apparently still has problems with this code:

{{ $.Site.Params.images | absURL }}

I mentioned a couple of things to check, but without access to the site it’s just guesswork.

1 Like

I changed Params.images variable in config file to a simple string, now it works. I guess newer Hugo interpreter some variables as string only.

In v0.125.0 we fixed a bug where, unlike urls.AbsLangURL and urls.RelLangURL, the urls.AbsURL and urls.RelURL functions did not return an error when unable to cast the argument to a string. They checked for an error, but didn’t tell you about it.

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