Debug hugo and content (Page and Site)

hugo 115.4


content
└── post
    ├── img
    │   ├── dx
    │   │   ├── ab.webp
    │   ├── z.png
{{ $imagePath := printf "%s" "img/dx/ab.webp" }}
{{- $img := resources.Get $imagePath -}}
{{ printf "%s" $img }}

%!s(<nil>)


{{ with $.Page.Resources.ByType "image" }}
  {{ range . }}
    {{ .RelPermalink }}
    {{ printf "%s" .RelPermalink  }}
  {{ end }}
{{ end }}

and or

{{ with $.Page.Resources.GetMatch "**/ab.*" }}
  {{ printf "%s ," .RelPermalink  }}
{{ else }}
{{ end }}
  • nothing is printed

{{ printf "%#v" $.Site }}
{{ printf "%#v" $.Page }}
&page.siteWrapper{s:(*hugolib.Site)(0xc0008a1e40)} 
&hugolib.pageForShortcode{PageWithoutContent:(*hugolib.pageState)(0xc00620d710), TableOfContentsProvider:(*hugolib.pageState)(0xc00620d710), ContentProvider:(*page.nopPage)(0xc000054910), toc:"

* [abc](http://localhost:1313/ab/#abc)

", p:(*hugolib.pageState)(0xc00620d710)}

{{ with $page.Resources.GetMatch }}
  {{ printf "%s ," .RelPermalink  }}
{{ else }}
{{ end }}
  • parse failed undefined variable “$page”

How to get the page images shown/ accessible?

How to get access to the images in assets?

It is impossible to answer your question without additional context.

Please post a link to the public repository for your project.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Hello Joe,
I will try to create it again as a minimal example … but that takes some time


some more context:

  • the markdown/figure is used in a _index.md file (not a index.md if that would make a difference?)
  • the code is executed within a figure.html / shortcode (which is all the same like the default figure shortcode
  • but tries to get a image by {{- $img := .Page.Resources.GetMatch (.Get "src") -}} at the top to get information like $img.Height and being able to do $img.Resize )

Without the Resources functionality the shortcode works like expected
(- but it uses the figure attributes, only)


What I noticed is that within the shortcode there seems to be no access to the page resources/context/content

  • how to passthru the page context into the figure shortcode?

I still can’t answer your question. Feel free to share your existing repository, privately if you wish.