Rendering Markdown from Space Lua

Hello!

I’ve been making a little utility function that would create a template with pages that have a specific tag on them and order them by date of creation. That is finally working after a day or so of tinkering, but I also wanted to add a heading above the template in markdown and I can’t seem to find any way of doing it in Space Lua. I don’t know much Space Lua or Lua in general, so I may just be missing something that’s very easy.

This is the function I’m working on:

sl = sl or {}

sl.taggedPagesTemplate = function(tag)
  return template.each(
    query[[
      from index.tag(tag)
      order by created
    ]],
    templates.pageItem
  )
end

So, in essence, what I’d like it to do is first display a heading in markdown and then render the template:

Heading

  • [[page1]]
  • [[page2]]

Any help is greatly appreciated!

template.each just returns a string containing rendered markdown. You can just prepend markdown, don’t forget a newline tho.
That’s the magic of space lua, it doesn’t have any weird abstractions.

${"# Heading\n" + template.each(query[[from index.tag "page" limit 3]],template.new[==[
    * ${name}
]==])}

(Template example from the docs, but you get the point)

1 Like

Thank you so much!

This is probably as simple as it gets. Don’t know why I haven’t thought of this at all, but I guess overthinking doesn’t do anybody any good :laughing:.