gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.96k stars 7.47k forks source link

Link hook has no context to current page #12884

Open christianlupus opened 2 hours ago

christianlupus commented 2 hours ago

I have a homepage that I want to customize with render hooks for a certain section. I created the corresponding folder layouts/glossary/_markup/ and a file render-link.html inside. According to the documentation (or at least my understanding of it), in the render hook, I should have access to .Page that points to the page containing the link.

If you put a (debug) script in the render-link.html file containing

The page is {{ .Page }}.

and create a link in the section (glossary in my case), you will see, that .Page is the page object of the pointed-to page.

So, either one should be done in my opinion

  1. Fix the behavior to have access to the current page where the link is actually output
  2. Update the docs to reflect the fact that the .Page refers to the page that the link points to

Personally, I think it would be useful to have access to the local page, I see benefits for both solutions.

What version of Hugo are you using (hugo version)?

I use the NPM package hugo-extended@0.134.3.

$ hugo version
hugo v0.134.3-5fb333b9f5ff4ec018f9d78910177d0bec1befb0+extended linux/amd64 BuildDate=2024-09-19T14:28:20Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

This is the latest version I can find on NPM and the latest version here on GitHub. I have not build hugo from scratch to test on master.

bep commented 2 hours ago

I should have access to .Page that points to the page containing the link.

That's is how it works. I'm guessing a little, but what I think you mean is that if you do something like this in the homepage template:

{{ range site.RegularPages }}
   {{ .Content }} // the page you as .Page in the render hooks for .Content is "." (e.g. `/posts/page1`) and not $ (the home page)
{{ end }}

You expect the .Content in the range loop to get the home page in the hooks.

Does the above describe the problem?