Include section of page

my usecase:
I have daily page template from which I create page every day and fill out some notes.
I would like to have overview of all notes from every day but not whole page, only particular part.
(btw I found out Selective include with space script only after I created this. while it is more universal, you need to add special section tags.

this is the template:

tags: template
{{#let @h = {"pos": pos, "level": level, "page": page}}}
{{#let @nextHeader = {header where pos > @h.pos and level <= @h.level and page = limit 1}}}
{{#let @endPos = count(@nextHeader) > 0 ? at(@nextHeader, 0).pos - 1 : -1}}
{{getLinesFromPage(, pos, @endPos, false)}}

and this is getLinesFromPage function:

silverbullet.registerFunction({name: "getLinesFromPage"}, async (pageName, start, end, withHeader = true) => {
  const p = await syscall("space.readPage", pageName);
  end = end >= 0 ? end : p.length;
  console.log(`from ${pageName}: ${start} ${end}`)
  if(!withHeader) {
    start = p.indexOf("\n", start);
  return p.substring(start, end ? end : p.length);

now I can query any headers and render them as this template and I will see everything that comes after this header up to end of file or another header that is same or lower level.

can this be made simpler?
also where do you usually store your functions? I wanted to have the function definition in the template file but it looks that if page has tag “template” functions are not read from it.