tpb
August 1, 2023, 3:25pm
1
I want to create a template with a query for all tasks with an assigned property set to the current page.
This works:
#+BEGIN_QUERY
{:title "Assigned"
:query [:find (pull ?b [*])
:in $ ?current-page
:where
(property ?b :assigned ?current-page)
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
:inputs [:current-page]}
#+END_QUERY
But because current-page or query-page lower cases the page title, I have to assign tasks to “@john ” instead of “@John ”, which does not look great, and is easy to forget, which would result in missing results.
Is there a way to lower case the assigned value in the query so it matches the current-page?
There is an original-name property if that is what you need.
so between :where
and (property ...
add:
[?p :block/name ?current-page]
[?p :block/original-name ?name]
Then change (property...
to
(property ?b :assigned ?name)
Otherwise… I had to dig this one up from discord lol.
Here’s a query that uses regex to search case insensitive.
#+BEGIN_QUERY
{:title "Assigned"
:query [:find (pull ?b [*])
:in $ ?current-page
:where
[?b :block/properties ?prop]
[(get ?prop :assigned) ?assigned]
[(str "(?i)" ?current-page "$") ?regex_s]
[(re-pattern ?regex_s) ?regex]
[(re-find ?regex ?assigned)]
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
]
:inputs [:current-page]
}
#+END_QUERY
tpb
August 1, 2023, 4:07pm
3
I also came across a similar query using regex, but I do not understand it at all (the query, I kind of understand regex).
original-name should work fine for my purposes though, thank you!
Fair enough
[?b :block/properties ?prop]
[(get ?prop :assigned) ?assigned]
is equivalent to (property ?b :assigned ?current-page)
except that it puts the property value in a variable instead of matching it against ?current-page
.
[(str "(?i)" ?current-page "$") ?regex_s]
[(re-pattern ?regex_s) ?regex]
[(re-find ?regex ?assigned)]
is to make the regex work.
The rest of the query should be familiar