Custom sorting - joining arrays

I have a list page where I need to sort the lists of content in a specific way. From my Googling, it seems that I am unable to do the sorting required.

What I want to achieve is the ability to sort on four (maybe more in the future) different parameters. Since I don’t seem to be able to do this, I have created four different arrays each with a specific attribute (one that I wanted to sort on). My plan is to join the arrays together in the order (sort order) that I want them.

I am currently grappling with how I create a function to compare two arrays and only leave the values that are in neither (not union or intersect) and a function that allows me to join multiple arrays.

Would someone be able to point me in the right direction please?

Three suggestions:

  1. Follow the advice in Requesting Help. Your description can mean so many scenarios, I personally need to know what you are working with to help.
  2. Nested ranges.
  3. complement | Hugo

I get your point. I apologise if it occurs I wasn’t being clear.

To be exact, I have many pages with different attributes. I want to be able to list all the pages but sort by multiple attributes. This is important because some pages need to be public but they are not complete (some attributes are missing), I do not want to show them at the top of the page but I want them to be on our public site. For example, some pages do not have an image, some do not have all the text required etc. Sorting by multiple attributes does not seem possible.

The way I have found that would allow me to do this is filter the pages into separate arrays (using where) that contain the missing attributes and then reconstruct one big array in a specific order:

  1. complete pages
  2. pages that have some attributes missing
  3. pages that do not have an image

I get the feeling I wasn’t clear enough in my last post, so I will try again.

I have approx 50 articles that I would like to present on a list page. Most articles are complete, some articles are not complete, some of them do not have a banner image.

I would like to sort the articles by:

  1. PublishDate
  2. whether they are complete or not
  3. whether they have a banner image

Is it possible to sort by multiple page params or attributes of a page?

If all of the items that you want to order on are things you can determine off a front matter param, then you can nest many .ByParam. For example:

{{ range (site.RegularPages.ByParam "foo-1").ByParam "foo-2") }}
1 Like