Blocks that reference pages of some property by name or alias

I have a namespace with pages Parent and Parent/Child. Parent has alias P, Parent/Child has alias C. A big limitation of namespaces is that I cannot reference Parent/Child as [[C]] and have it show in the linked references of Parent, so I am trying to use page properties to fix that.

For that, I create two separate pages Parent and Child and I am going to put type:: commontype on top of both pages. Now I would like to write something like:

- some block [[Child]]
- some other block [[C]]
- some block [[Parent]]
- some block [[P]]

and do an advanced query that outputs all blocks that have references (by name or alias) to any page with page tag type:: commontype, so that it outputs all references to both Parent or Child (all of the above), as the linked references of a namespace would.
How can I do this?

  • Well done for dropping namespaces in such a case.
  • Let’s begin with something like this:
    {:query [:find (pull ?b [*])
         [?p :block/properties ?props]
         [(get ?props :type) ?type]
         [(= ?type "commontype")]
         (or-join [?b ?p]
           [?b :block/refs ?p]
             [?b :block/refs ?a]
             [?p :block/alias ?a]
1 Like

Thank you, that works!
I have two further questions:

  1. What if I want to exclude the blocks at the top of the children pages that have type:: commontype from the query results (since these only serve to tag the page and don’t have any important info)?
  2. I would like to have a result similar to what {{namespace Parent}} would give me. To simplify, let’s say I just want to have list of the children pages of parent (i.e., all the pages with type:: commontype except page Parent), and I would like to just have clickable links to the children without a table or additional info. If Parent is aliased with P I can do the following query:
  :query [:find (pull ?p [*])
          [page-property ?p :type "commontype"]
          (not [page-property ?p :alias "P"])]

However, this gives me the results in table form and at least a “Page” column. Wouldn’t it be possible to have a result similar to what {{namespace Parent}} prints?

1 Like