.Path when the page is backed by a file is deprecated

Hi there, I really don’t understand this error message. Do I need to update my layout?

(ins)[hendry@t14s dabase.com]$ rg Path layouts/
layouts/partials/footer.html
3:{{ $editURL := printf "%s/edit/master/content/%s" "https://github.com/kaihendry/dabase.com" .Path }}
4:{{ $commitsURL := printf "%s/commits/master/content/%s" "https://github.com/kaihendry/dabase.com" .Path }}
(ins)[hendry@t14s dabase.com]$ hugo --panicOnWarning
Start building sites …
hugo v0.92.0+extended linux/amd64 BuildDate=unknown
WARN 2022/01/29 18:20:42 .Path when the page is backed by a file is deprecated and will be removed in a future release. We plan to use Path for a canonical source path and you probably want to check the source is a file. To get the current behaviour, you can use a construct simlar to the below:

  {{ $path := "" }}
  {{ with .File }}
	{{ $path = .Path }}
  {{ else }}
	{{ $path = .Path }}
  {{ end }}


^C
(ins)[hendry@t14s dabase.com]$ hugo version
hugo v0.92.0+extended linux/amd64 BuildDate=unknown

:roll_eyes:

Could you please explain, how to make the message more obvious? We sometimes have issues having self-explanatory error messages, but to me, this looks quite such (self-explanatory):

  • Look for the .Path variable.
  • Replace with the code that is offered as a replacement.
  • Be happy it works again.

You have somewhere in your layout a range that goes over the page content and thepageyouareworkingwith.Path stopped existing. Because it is the same as .File.Path which that code sample would add or fall back gracefully if you are somewhere completely else.

If that still does not help you, please post the whole layout that throws the warning. But you will see that the end result is exactly the same :wink: Someone will replace your .Path with .File.Path.

And as I wrote above, if that error message is really so hard to understand for a non-developer (sorry if I sorted you into the wrong house here) please let us know how to do it better.

1 Like

The message doesn’t indicate which layout file needs updating.

panicOnWarning doesn’t offer a better error message.

Tbh I am quite confused how to update dabase.com/footer.html at master · kaihendry/dabase.com · GitHub … the code replacement doesn’t quite make sense to me.

Yes, it does.

Error: Error building site: failed to render pages: render of “page” failed: execute of template failed: template: _default/single.html:12:3: executing “_default/single.html” at <partial “footer” .>: error calling partial: “/home/jmooring/code/hugo-testing/layouts/partials/footer.html:3:96”

It’s telling you that the there’s a problem on line 3, column 96 of footer.html

As the warning suggests, wrap using with .File

<footer>
  <p>Comments? <a href="mailto:hendry+dabase@iki.fi?subject={{ .Title }}">Email Kai Hendry please</a> or <a href="https://twitter.com/kaihendry/">@kaihendry on Twitter</a></p>
  {{ with .File }}
    {{ $editURL := printf "%s/edit/master/content/%s" "https://github.com/kaihendry/dabase.com" .Path }}
    {{ $commitsURL := printf "%s/commits/master/content/%s" "https://github.com/kaihendry/dabase.com" .Path }}
    <a href="{{ $editURL }}">Edit this</a>
    |
    <a href="{{ $commitsURL }}">File history</a>
  {{ end }}
  <small>Last Build time: {{ now.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</small>
</footer>

Your site should have been structured this way from the beginning, because it doesn’t make sense to offer edits to pages that are not backed by files. For example, going to https://dabase.com/tags/ and pressing the edit link currently throws a 404 error.

When I run hugo --panicOnWarning (see initial post), I don’t get that error, unless I am missing something?

Thank you very much! Many thanks Mr Mooring https://discourse.gohugo.io/t/path-when-the-pa… · kaihendry/dabase.com@f5cd6a5 · GitHub

I don’t know what to tell you. With v0.92.1

hugo --panicOnWarning 

And when I build your site (before you made the corrections to footer.html)…

…the information is there

execute of template failed: template: partials/footer.html:10:44

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