How to refer to the published page when rendering content of another page

Given:

  • Hugo publishes a regular content page: content/page.md.
  • Its layout file is: layouts/_default/single.html.
  • This layout file contains the following code:
{{ $bundle := $.Site.GetPage "snippets" }}
{{ range $bundle.Resources.Match "snippet.md" }}
    {{ .Content }}
{{ end }}
  • content/snippets/snippet.md uses a shortcode:
Lorem ipsum {{< example >}} dolor sit amet.

Then:

  • In layouts/shortcodes/example.html, the $.Page variable refers to content/snippets/snippet.md.

Question:

Is there any variable available in layouts/shortcodes/example.html that refers instead to content/page.md?

Hello,

I reworded the title of the topic because it was too long.

If you think that I misunderstood the issue then please provide a concise title.


Now regarding the question I think that it would be best if you could provide a sample repo that showcases what you’re trying to do. As in the exact structure of the Page Bundle with its headless bundle (snippets) and the relevant shortcode.

So that people can take it for a spin and see.

3 Likes

Thank you. I realize my question was too specific, so I rewrote it in more generic terms. Hope it makes more sense now.

Again, it would be best to publish a repo. You haven’t provided the contents of layouts/shortcodes/example.html. As far as I know, shortcodes are meant to be used in regular content files and not included through layouts.