I had something like this figured out at one point. I remember it required using several plugins community plugins including Dataview, Templater, maybe Metadata Menu. You can access a note’s YAML properties using Dataview’s API, but it requires a bit of custom js inside your template, which you can do with Templater.
I can’t write the code for you, as I’m novice with js, but I will link to my very first two posts on this forum, which in part documents my process figuring out how to make something similar work for myself.
Here are those posts:
BTW—there’s usually a JS wizard or two hanging around the Obsidian Discord if you want to give that a try.