Querying pages with hierarchy

Hi everyone,

I have created the following query, in order to have the list of all sub pages of the current page, with the objective (not implemented yet) to be able sort them by created date & by property (the current “Hierarchy” block is not suited to my workflow as it is at the bottom of the page, and does not display enough information)
However, while the query works well with pages without hierarchy, I have a “blue screen” (and everything in the logseq interface disappear) whenever I click on the link of a subpage.

Is this a bug, or am I doing something wrong?

#+BEGIN_QUERY
{:query [:find (pull ?p [*])
:in $ ?parent
:where 
  [?p :block/name ?name]
  [(clojure.string/starts-with? ?name ?parent)]
  [(clojure.string/includes? ?name "/")]
]
:inputs [:current-page]
:view
 (fn [results]
 [:div.flex.flex-col
(for [{:block/keys [name original-name]} results]
    [:a {:href (str "#/page/" name)}
        original-name]
   )])}
#+END_QUERY

Thanks for your help !

1 Like

Hi, were you able to figure this out?
I’m looking for a similar query.

this query doesn’t work with a parent page which is already a child of another parent. Example below - I want to list Child pages in query

  • Root
    • Parent
      • Child1
      • Child 2

To answer the original question, it’s in the link you create. You have to substitute / with %2F.
Like so:

[:a {:href (str "#/page/" (clojure.string/replace name "/" "%2F"))} original-name]

Also you probably don’t need that whole view section either way.

The following query is also much more straight forward:

#+BEGIN_QUERY
{:title "Current Members"
 :query [:find (pull ?p [*])
  :in $ ?current
  :where
   [?c :block/name ?current]
   [?p :block/namespace ?c]
 ]
 :inputs [:query-page]
}
#+END_QUERY