Having problems with Leaf Bundles and Permalinks

Hello, I am building a simple restaurant website and I’m having issues. Basically, on my homepage I want to render a list of all the types of food from the menu. Let’s say for now that the available types of foods are burgers and salads. I used this site from the documentation in hopes of helping me, but it didn’t. Here’s what my project structure currently looks like:

  • content
    • burger
      • first-burger
        • image.jpg
        • index.md

I would be adding the salad folder right under the burger folder. What I’m trying to do now is render a list of burgers on my homepage and display their title and their image(image.jpg).

I inserted the code from the mentioned website:

  {{ range .Pages }}
  <li>
    <a href="{{.RelPermalink}}">{{.Title}}</a>
  </li>
  {{ end }}

But that just renders a link with the text Burger and leads to http://localhost:1313/burger/ instead of http://localhost:1313/burger/first-burger. What am I doing wrong? I tried setting permalinks, adding/changing index.md and _index.md… I tried different variables but nothing works… I mean I understand that I am looping through all Pages instead of all Burgers, but I can’t find any information on how to specifically select the Burgers leaf bundles?

Haven’t tested this, but try it and see (change the class name foo and bar to your own if you need to style the layout. Also, change the image size 300x200 to your liking).

<div class="foo">
{{- range where site.RegularPages "Section" "burger" -}}
<div class="bar">
{{- with .Resources.GetMatch "*.jpg" -}}
    {{- with .Fill "300x200 webp" -}}
      <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
    {{- end -}}
  {{- end -}}
<li>
    <a href="{{.RelPermalink}}">{{.Title}}</a>
  </li>
</div>
{{- end -}}
</div>
1 Like

This worked absolutely beautifully! Thank you

Welcome. Just duplicate the code and change burger to salad for the salad section. If you need to limit the number of posts showing per section (e.g. first 5), see the example below

1 Like

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