Search code examples
hugogo-html-template

Sort on user defined properties


I'm using hugo v0.15 I'm trying to sort pages on custom property.

I define my subpages as following:

+++
title= "bla bla bla"
parent = "parent"
index = 0 # each page is assigned a unique index
+++

And in my parent template as following:

{{ range sort .Site.Pages ".Params.index" }}
    <a href="{{.RelPermalink}}">
          {{.Title}} {{.Params.index}}
    </a>
{{end}}

this doesn't fails at compilation, but the list is rendered empty. what am i missing?


Solution

  • Well, i was walking in the wrong direction. I discovered that there's a default parameter is there just to be used for sorting, "weight"

    So, the fix is:

    use "weight" instead of "index"
    

    and use weight

    {{ range sort .Site.Pages ".Weight" }}
    

    this fixed my issue, but there's still a problem using user defined properties for sorting.