Liquid: filter collection where not null?



In my front matter I have:

layout: default
title: "Services"
    order: 2

The top-navigation is only on some pages. Using liquid I want to filter all site pages which have a top-navigation property and sort by order.

I’m trying sort:'top-navigation.order' but that’s throwing an exception of undefined method [] for nil:NilClass.

How can I filter for pages that have top-navigation and then sort?

Stack overflow post: