Page.Dir is deprecated ... Use .File.Dir


When building my website, I get this warning:

~/code/ $ hugo serve
Building sites … WARN 2020/03/30 18:06:07 Page.Dir is deprecated and will be removed in a future release. Use .File.Dir


For this question, the (tagged) relevant repos are

  • My repo,, on commit e8efe14
  • The hugo learn theme, which at question time, is on commit b5c759a

Version info

$ hugo version
Hugo Static Site Generator v0.65.3/extended darwin/amd64 BuildDate: unknown


A similar question about .File.Dir is here (not linked with markdown due to new user): [Error: What to replace .File.Dir with in hugo-book](

Using the bash provided by @bep in that post:

$ findDir () { find . -name "*.html" | xargs grep "\.Dir"; }
$ findDir
./layouts/shortcodes/attachments.html:	{{ range (readDir (printf "./content/%s%s" .Page.File.Dir ($.Scratch.Get "filesName")) ) }}
./layouts/shortcodes/attachments.html:		{{ $fileDir := replace $.Page.File.Dir "\\" "/" }}
./layouts/partials/header.html:                    <a class="github-link" title='{{T "Edit-this-page"}}' href="{{ $Site.Params.editURL }}{{ replace $File.Dir "\\" "/" }}{{ $File.LogicalName }}" target="blank">

But these .Dir usages are the exact same as the ones in the theme, and the theme does not have this issue. To demonstrate (with both repos downloaded to a ~/code folder:

$ diff <(cd ~/code/; findDir) <(cd ~/code/hugo-theme-learn/; findDir)


Which file is causing this warning and how can I fix it?

Probably this one.

Cheers @pointyfar that was it. I thought that “Dir” was a string there, not a variable.

For future readers, this was the offending line:

		{{ $rootPage := where .Page.Pages "Dir" "" }}

Changing it to File.Dir fixed.

A short explanation:

Yes, it is “technically” a string, but the way where works, it would evaluate each of .Page.Pages, and for each element, look at whether the page variable “Dir” matches, etc.

1 Like

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