Page's .URL is deprecated

WARN 2019/09/07 23:41:09 Page’s .URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url.

Hello!

I am not sure whether you are asking a question. But the output is the expected behaviour. Just replace .URL in your template files with .Permalink or .RelPermalink.

How to {{.Paginator.Next.URL}} ? Change to?

Read what @Grob said

I have changed the .URL to. Permalink … and nothing has changed

If I am properly informed .URL for .Paginator is correct.

This works for me:

{{ if .Paginator.HasNext }}
  <a href="{{ .Paginator.Next.URL }}">Next</a>
{{ end }}

If you still get the error message you mentioned above, my guess is that .URL is used in another template file.

I have code like this

 <ul id="post-list" class="archive readmore">
<h3>{{ .Site.Params.readMore | default "Read more" }}</h3>

{{ $kind := where .Site.RegularPages "Section" "!=" "" }}
{{ $othr := where $kind "URL" "!=" .URL }}
{{ range first 10 $othr }}
    <li>
        <a href="{{ .URL }}">{{ .LinkTitle }}<aside class="dates">{{ .Date.Format "Jan 2 2006" }}</aside></a>
    </li>
{{ end }}

Ok, I see what you mean.

As mentioned above you just need to replace .URL with .Permalink, but also "URL" with "Permalink".

This snippet works for me with Hugo 0.58.1:

{{ $kind := where .Site.RegularPages "Section" "!=" "" }}
{{ $othr := where $kind "Permalink" "!=" .Permalink }}
{{ range first 10 $othr }}
    <li>
        <a href="{{ .Permalink }}">{{ .LinkTitle }}<aside class="dates">{{ .Date.Format "Jan 2 2006" }}</aside></a>
    </li>
{{ end }}
1 Like

Thanks solved kang hihihi

so I can leave it like that?

            {{ if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
                  {{ if .Paginator.HasPrev }}
                  <a href="{{.Paginator.Prev.URL}}"><<< new entries &nbsp;&nbsp;</a>
                  {{ end }}
                         - Seite {{ .Paginator.PageNumber }} von {{ .Paginator.TotalPages }} - 
                {{ if .Paginator.HasNext }}
                  <a href="{{.Paginator.Next.URL}}">&nbsp;&nbsp; old entries >>></a>
                {{ end }}
            {{ end }}

That’s fine.

But I have something like that in my top navigation:

        <ul>
        {{ $currentPage := . }}
            {{ range .Site.Menus.main }}
            <li>
                <a class="menu-nav-item{{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }}-active{{end}}" href="{{.URL}}">{{ .Name | upper }}</a>
            </li>
            {{ end }}
        </ul>

and if I replace the .URL there I get

execute of template failed: template: partials/header.html:104:150: executing “partials/header.html” at <.Permalink>: can’t evaluate field Permalink in type *navigation.MenuEntry

Is this also to stay like is?
Hugo keeps complaining …

Page.URL is not the same as .Paginator.URL or .menu.URL.

Only the first is deprecated. The others are what one is supposed to use.

Also I am archiving this old topic.