Hugo

Is it possible to access the frontmatter of an md file when its a page resource?

Hi Happy Hugo peeps!

I am trying something new and have not been able to work it out with the docs. I am trying to use page resources with markdown files. So say you have the following:

Leaf Bundle

  • index.html
  • gizmo.md
  • widget.md

Can I access front matter values in gizmo.md and widget.md? Or only in the index.md?

I seem to be getting closer…but I still don’t know if this is the right way to go.

{{ $gizmo := .Resources.Match "gizmo.md" }}

            {{ with $gizmo }}

                {{ range . }}

                    {{ .Title }}

                    {{ .Params.description }}

                {{ end }}

            {{ end }}

Any thoughts?

go this way

Hi Gerhard. Thanks for the feedback.

I was using .Site.GetPage with Sections and Branch Bundles and that worked well.

However, that does not seem to work with a Leaf Bundle. I will continue to test and see what I can figure out.

Update: I just found this in the docs:

If the page retrieved by .GetPage is a Leaf Bundle, and you need to get the nested page resources in that, you will need to use the methods in .Resources as explained in the Page Resources section.

So, with that in mind, is my above solution the right approach?

Thanks,

Jeff

from my figure shortcode:

{{ $pic := $.Page.Resources.GetMatch (.Get "src") }}

<img src={{ $pic.Permalink }}  ...

This will find the right image in category lists too

{{ with .Site.GetPage "/blog/my-post.md" }}
 {{ $pic := .Resources.Match "**/Sunset.jpg"  }}
    <img src={{ $pic.Permalink }}  ...
{{ end }}