Page ListChildren with hidden in navigation filter in sightly




I am using the below code snipped to iterate over my pages and list out the children

<template data-sly-template.descendants="${@ page}">
  <ul data-sly-list.child="${page.listChildren}">
       <li data-sly-call="${descendants @ page=child}"></li>
<div data-sly-call="${descendants @ page=currentPage}" data-sly-unwrap></div>

But ${page.listChildren} gives all the pages including the pages that are hidden in the Navigation too,

is there way to filter the pages that are hidden in navigation with in Sightly?

Please help

Accepted Solutions (1)

Accepted Solutions (1)





Please use query builder to fetch the child pages in java and iterate the list of pages in sightly. Iterating over list in sightly is very simple and you can also bind the resources returned from query builder to sling models.

Using query builder, you can fetch pages under a page (using path property) and exclude pages using property field (property.operation=equals for checking value equals, property.operation=not for property not present, property.operation=like for property contains the value) and using property, you can list the pages of specific resourcetypes.

Use p.limit=-1 to list all the results (unless it will fetch only 10 results by default) and also add p.guessTotal=true. Also create oak index so that query builder runs fine and wont slow down the instance if the pages are very large.

Please check Query Builder API for more details

Hope this helps !

Answers (1)

Answers (1)



Build a Java backend Query pages where you are interested in. Exclude the pages you do not want. That way - you have much better control over your data.