{%- comment -%} Include as: {%- include nav.html pages = pages key = key -%} Depends on: include.pages, include.key, page, site. Results in: HTML for the navigation panel. Includes: sorted_pages.html Overwrites: nav_pages, first_level_pages, second_level_pages, third_level_pages, node, children_list, child, grand_children_list, grand_child. {%- endcomment -%} {%- assign nav_pages = include.pages | where_exp: "item", "item.title != nil" | where_exp: "item", "item.nav_exclude != true" -%} {%- include sorted_pages.html pages = nav_pages -%} {%- assign first_level_pages = sorted_pages | where_exp: "item", "item.parent == nil" -%} {%- assign second_level_pages = sorted_pages | where_exp: "item", "item.parent != nil" | where_exp: "item", "item.grand_parent == nil" -%} {%- assign third_level_pages = sorted_pages | where_exp: "item", "item.grand_parent != nil" -%} {%- comment -%} The order of sibling pages in `sorted_pages` determines the order of display of links to them in lists of navigation links. Note that Liquid evaluates conditions from right to left (and it does not allow the use of parentheses). Some conditions are not so easy to express clearly... For example, consider the following condition: C: page.collection = = include.key and page.url = = node.url or page.grand_parent = = node.title or page.parent = = node.title and page.grand_parent = = nil Here, `node` is a first-level page. The last part of the condition -- namely: `page.parent = = node.title and page.grand_parent = = nil` -- is evaluated first; it holds if and only if `page` is a child of `node`. The condition `page.grand_parent = = node.title or ...` holds when `page` is a grandchild of node, OR `...` holds. The condition `page.url = = node.url or ...` holds when `page` is `node`, OR `...` holds. The condition C: `page.collection = = include.key and ...` holds when we are generating the nav links for a collection that includes `page`, AND `...` holds. {%- endcomment -%}