How to sort a range over a headless bunldle

Given a content structure as follows:

└── serviceA
    └── //headless:true, weight: 3
    └── resources
└── serviceB
    └── //headless:true, weight: 1
    └── resources
└── serviceC
    └── //headless:true, weight: 2
    └── resources

I want to create a “layouts/services/list.html” template that can range over the headless bundles where they are sorted by a param “weight”

I can get the content to display correctly with:

{{ define "main"}}

//content from
{{ .Content}}

{{ $page := . }}
{{ range (where (readDir (print "content/" .File.Dir)) ".IsDir" true ) }}
{{ with $page.GetPage .Name }}

//content from each
{{ .Content}}
{{ end }}
{{ end }}


However I am not sure how to pull off the sort within the range.

Is there a better way to go about this?

Instead of using headless pages, you could try the new build options, specifically the example with listing pages without publishing them. Then sorting by weight is straightforward.

1 Like

@pointyfar looks great thanks

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