Hi everyone! Unfortunately I can’t find a solution to this problem, despite searching the forums for days. However, I’m sure the solution can’t be too complicated - But maybe my trials are I’m don’t know Javascript too well, which is why I’m struggling with the Syntax.
What I’m trying to do
I’m trying to create a template with templater that grabs exisiting frontmatter list and creates links to notes for each individual element.
Say, we are in a movie note and the frontmatter list contains names of actresses featured in the movie:
title: Batman Returns
year: 1992
starring:
* Michael Keaton
* Danny DeVito
* Michelle Pfeiffer
* Christopher Walken
* Michael Gough
* Pat Hingle
* Michael Murphy
Now, a templater template should grab the “starring” array and link a note to each of the elements, to cross reference the movie note with actors notes:
*Batman Begins* features [[Michael Keaton]], [[Danny DeVito]], [[Michelle Pfeiffer]], [[Christopher Walken]], [[Michael Gough]], [[Pat Hingle]] and [[Michael Murphy]].
Things I have tried
While templater natively allows to reference frontmatter arrays like so:
<% tp.frontmatter.starring %> = Michael Keaton,Danny DeVito,Michelle Pfeiffer,Christopher Walken,Michael Gough,Pat Hingle,Michael Murphy
<% tp.frontmatter.starring[0] %> = Michael Keaton
Executive commands in templater, however, don’t. I’m getting no output with following lines:
<%* tp.frontmatter.starring %>
<%* tp.frontmatter.starring[0] %>
Nonetheless they don’t thow an error either. So it seems that the array is detected somehow.
Anyways, my approach would be to iterate through the array in a for loop and put “[[” and “]]” around each entry. As far as I know , for loops in templater are only possible in executive commands. So I tried for days to get access to the frontmatter array. The closest I got is from a solution posted here: Change yaml list with templater
It accesses the frontmatter externally in order to change it. Which in my case is quite an overkill, I think. Also, I really don’t know how to implement a for loop here:
<%*
await app.fileManager.processFrontMatter(tp.config.target_file, (fm) => {
const index = fm.starring?.indexOf("Michael Keaton");
const arrLen = fm.starring?.length;
// Changing the metadata
if ( index != undefined ) fm.starring[arrLen - 1] = "Test" ;})
%>
Any ideas for an easy solution here?
All my best!