Rendering Multiple Pages

Hi,

In my layouts, I have entered code in this structure (which works perfectly fine, but in the future, there will be a lot more folders to add).

Where my folder structure is in the following format:

content/cloud/

  • cloud-master (3 files nested inside)
  • cloud-novice ( 2 files nested inside)
  • cloud-rookie (5 files nested inside)

{{ with .GetPage "cloud-master" }}
   {{ range .Pages }}
       <h1>{{Params.title}} </h1>
       <p>{{Params.description}}</p>
  {{end}}
{{end}}


{{ with .GetPage "cloud-novice" }}
   {{ range .Pages }}
       <h1>{{Params.title}} </h1>
       <p>{{Params.description}}</p>
  {{end}}
{{end}}

{{ with .GetPage "rookie" }}
   {{ range .Pages }}
       <h1>{{ Params.title }} </h1>
       <p>{{ Params.description}}</p>
  {{end}}
{{end}}

I am trying to find a way where I can render "cloud-master “cloud-novice” “cloud-rookie” directories all in one shot instead of having to call the folders separately. Please Help.

Please use fenced code blocks when posting code. Or the little button that has the </> symbol. When creating or editing a post, the preview pane shows you a preview.

Found the solution:

{{ $cloudSections := slice "cloud-master" "cloud-novice" "cloud-rookie" }}

{{ range $cloudSection := $cloudSections }}
  {{ with $.GetPage $directory }}
    {{ range .Pages }}
      {{ .Title}}

      {{ .Description }}

    {{ end }}
  {{ end }}
{{ end }}

Is this the homepage or list page?

It is a Home Page. Now my next challenge is building a Side-Nav for my child pages… I am looking into the built in Ancestor Function Hugo has (extremely powerful, I used it for my breadcrumbs partial). I know there are a bunch of libraries that can do it for you but I would like to build one of scratch. I have used libraries before but I feel like when you build it off scratch you learn a lot more. Do you recommend any resources?

I am sorry instead of

{{ with $.GetPage $directory }}

I used:


{{ with $.GetPage $cloudSection }}

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