5

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?

Amr M. AbdulRahman
  • 1,820
  • 3
  • 14
  • 22

2 Answers2

4

but there's still a problem using user defined properties for sorting.

Create your custom, user defined parameter in the page front matter, such as "my-param" below:

+++
title = "The page title"
date = 2017-08-24T22:14:52-07:00
author = "Me"
banner = "img/default.jpg"
my-param = "100"
+++

In your template, add something like the following:

{{ range $paginator.Pages.ByParam "my-param" }}
acronym
  • 71
  • 4
3

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.

Amr M. AbdulRahman
  • 1,820
  • 3
  • 14
  • 22