Programmatically generate files from dataview and apply template

What I’m trying to do

I have a bunch of notes with properties, all of which are links. I’d like to generate two levels of “Table of Contents”, one that summarizes the unique values per property, and one for each unique value listing notes with that property value.

So, for example, if I have three notes as follows:
Note 1, year: “[[2019]]”
Note 2, year: “[[2020]]”
Note 3, year: “[[2019]]”

I then have a dataview query to produce:

Year Note

  • [[2019]]
  • [[2020]]

But I’d like to automatically, from this note, create notes for [[2019]] and [[2020]], that are populated with a template such that they display:

2019

  • [[Note 1]]
  • [[Note 3]]

2020

  • [[Note 2]]

I have a working template, but can’t figure out how to get it to populate automatically.

Things I have tried

I tried to use Templater to auto populate the “Year” notes with the folder template feature, but that relies on the notes being empty. Since the existence of these notes is realized by the creation of a property, meaning that they already have a title, I’m not sure how to make this work, other than pre-populating pages before I use them as properties, which won’t suit my workflow.

Thanks in advance!