Silverbullet 2.4.1 - I have the following query which displays any tasks for today using the taskitem template. When there are no tasks for today I would like to display "No tasks today".
${template.each(
query[[
from index.tag "task"
where not done
and page:match("%d%d%d%d%-%d%d%-%d%d$")
and string.split(page, '/')[2] == os.date("%Y-%m-%d")
order by page
]], templates.taskItem) or "No tasks today"}
No message appears.
if I run the query
${query[[
from index.tag "task"
where not done
and page:match("%d%d%d%d%-%d%d%-%d%d$")
and string.split(page, '/')[2] == os.date("%Y-%m-%d")
order by page
]] or "No Tasks today"}
the page name is area/date eg 'golf/2026-02-12'. I use the match pattern succesfully in many queries. The hyphen is already escaped. Maybe an empty query result is not nil and therefore the 'or' fails
from
index.tag 'task'
where
not done and
string.match(page, os.date('/%Y-%m-%d$'):gsub('-', '%%-'))
]],
templates.taskItem
)
or 'No tasks today'
}
Note: The or 'No tasks today' can't work as of now because the template.each returns string and in Lua empty string is truthy. @zef Is this intended behaviour for template.each?
```space-lua
-- priority: 40
template = template or {}
function template.each(tbl, fn)
local result = {}
for _, item in ipairs(tbl) do
table.insert(result, fn(item))
end
return #result > 0 and table.concat(result) or nil
end
```
Now the or 'No tasks today' should work. @zef Can I PR this? Or do you think it may be breaking change for some users?