There’s no way to do what you are trying to do. The problem is that even if you enable Twig processing in frontmatter: pages: frontmatter: process_twig: true (in system.yaml), when that runs the collection defined by the content items has not been processed.
Hi, thank you a lot for your answer, I will look into this.
What would the function look like? I understand how to call it, but not exactly how to write it.