I am working on filtering a task list by a page’s attribute. I am really close to having a solution. The issue that I am having is when I try to check the page attribute status == “open” I get false when I should get true.
For example, lets look at the output the following query.
Query
${query[[from p = index.tag "page" where p.name == "Server/2026" select p.status]]
Output
open
The output is what I would expect, as the frontmatter for that page has status: open
Now when I try to compare the output to the string “open” i get false
${query[[from p = index.tag "page" where p.name == "Server/2026" select p.status]]=="open"}
Output
false
I have a feeling that the string I am comparing is not formatted the same as the output for the query.
1- To retrieve (and test) the first value in the list (this is your case), you can do:
${table.concat(query[[from p = index.tag "page" where p.name == "Server/2026" select p.status]]) == "open"}
Other formulas are possible… but this one works!
To refresh the result: command System/Reload ou Ctrl+Alt+r.
2- To display a more explicit message, you can create a function in a space-lua (on another page). Exemple:
function libelleCh(valueTest)
local chExplicit = ""
if valueTest then chExplicit = "serveur démarré" else chExplicit = "serveur HS" end
return chExplicit
end
and call it in your inline code:
${libelleCh(table.concat(query[[from p = index.tag "page" where p.name == "Server/2026" select p.status]]) == "open")}
Then, to refresh the result: command System/Reload ou Ctrl+Alt+r.
I figured that out while I was waiting for the post to be approved.
Your exactly right, a query returned a table
So I needed to process the query with the table.concat() function to convert the output to a string
Here is my final query that displays unfinished tasks excluding ones that are on pages with status: closed
${template.each(query[[
from t = index.tag "task"
where not t.done
and not string.match(table.concat(query[[from p = index.tag "page" where p.name == t.page select p.status]]), "closed")
order by t.page desc
]], templates.taskItem)}