Sort by .Param and Weight

I’ve got a situation where I have pages with frontmatter like:

weight: 1
lname: Lastname

as well as

lname: Othername


weight: 2
lname: Bestname

I would like to range through the pages sorted first by lname and then by Weight. Ideally to get:

  • Lastname
  • Bestname
  • Othername

My problem at the moment is it appears that pages w/o an explicit weight frontmatter possibly get a default weight of zero (0)?

I would expect the default value to be nil, but perhaps Hugo knows about the weight param and gives you the right type.

I’m not sure what your issue is. Are you using a weight of 0 for some pages, and so you can’t tell whether a page actually has weight 0 by default or if you set it to 0?

Explicitly setting a weight to zero is not going to be helpul.

Page A (weight unset/0)
Page B (weight -1)
Page C (weight 1)

Sorted by weight:

Page B (weight -1)
Page C (weight 1)
Page A (weight unset/0)

The lighter ones float to the top, the heavier ones sink to the bottom, and the unset/0 pages are last.

You can set a default weight be “cascading it down” from your home page, section pages, or site configuration. For example:


weight = 42
kind = '*'

This will fill in the gaps; it will not override existing values.