I would like to create a template that has an embedded query. The embedded query looks for the name of the page the template is on, as the value of properties on other pages. The output is then formatted to show specific properties of those pages and sorted. I should note that I’ve sought help on Discord for this a few times and been given examples of :current-page but never working ones where it’s used to find values in page properties using an advanced query.
Breaking this down:
- I need a query that looks for a specified value in the property of other pages - I can do this.
- I need a query that specifies the value as the name of the current page - I can’t get this to produce results.
- I need to transform the output of the query - I can’t find a good write-up on how this works.
I’ll give a specific example.
I have the template “inventoryitem”. This consists of:
template:: inventoryitem
inventory/type::
inventory/title::
inventory/author::
inventory/actor::
I have the template “catalogue-simplequery”. This consists of:
template:: catalogue-simplequery
{{query (page-property inventory/type <% current page %>) }}
I have a page, “Shadowlands”.
This uses the inventoryitem template and it is the first block of the page.
inventory/type:: DVD
inventory/title:: Shadowlands
inventory/author::
inventory/actor:: "Anthony Hopkins"
I have the page DVD. This uses the template “catalogue-simplequery”.
It produces 0 results.
If I manually alter the template to read:
{{query (page-property inventory/type DVD) }}
It produces the output I expect.
Therefore it seemms that <% current page %> isn’t working as a replacement for DVD. I then tried replacing “DVD” with “dvd” in case the query is case sensitive, and it produces no results. I tried keeping the lower case “dvd” in the simple query and renaming the page using the title bar to “dvd” but it still provided no results.
Update:
I’ve found out that changing “DVD” to “dvd” in the “Shadowlands” page allows the <% current page %> query to work. Case sensitivity is clearly not being handled as I’d expect in simple queries (I’d expect everything like this to be totally case insensitve - but it isn’t). This didn’t work to fix the “book” advanced query down below.
I have the page “Call of the Wild”.
This uses the inventoryitem template and it is the first block of the page:
inventory/type:: Book
inventory/title:: Call of the Wild
inventory/author:: Jack London
inventory/actor::
I have the template “catalogue”. This consists of the advanced query:
template:: catalogue
#+BEGIN_QUERY
{
:query [:find (pull ?p [*])
:in $ ?current
:where
[?p :block/name _]
[?p :inventory/type ?current]
]
:inputs [:current-page]
}
#+END_QUERY
I embed the template “catalogue” on the page “Book”.
What I think this does (but presumably I’m wrong):
- pull every block and store as variable p
- filter variable p down to every block that has any value for block/name and store as variable p (since only pages have names) - this produces the results I’d expect.
- filter variable p to only instances where the property inventory/type has the value ?current (which should equate to “Book”, given it’s on the “Book” page).
This produces no results, instead of the result “Call of the Wild”.
After seeing example queries provided for querying for property values elsewhere, I created this query.
#+BEGIN_QUERY
{
:query [:find (pull ?p [*])
:in $ ?current
:where
[?p :block/name _]
[?p :block/properties ?property]
[(get ?property :inventory/type) ?invtype]
[(= ?current ?invtype)]
]
:inputs [:current-page]
}
#+END_QUERY
Still no results. I’m rather stuck and I’ve been butting my head against this problem with no progress for a while. If anyone can provide a working example of the actual query that will achieve what I want it to, I’d be very grateful.