Empty query message when using template

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"}

still get no message

Any help appreciated

Try to escape the - as %- in the match pattern... You can test. We cannot know what exact structure you mean...

${
  string.split(
    ('/foo/bar/baz/2026-03-19'): match('/%d%d%d%d%-%d%d%-%d%d$'),
    '/'
  )[2] == os.date('%Y-%m-%d')
}
true

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

What about something like the following?

${
  template.each(
    query [[
      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?

Put this somewhere...

```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?

I'm ok with this change, it can become a nice idiom.

PR 1899