How to list all values from a YAML key that link to a note

I have a template ‘paper’ that in the frontmatter contains something like this

- aut1
- aut2
- ...

I want to list all the authors for each paper, but also in a way that they redirect to the respective author notes. Specifically in the vault there is a folder names ‘Authors/’ that contains a note for each author.
So I want the authors in the ‘Paper’ template to show up like

[[Authors/<% tp.frontmatter.authors[0] %>]], [[Authors/<% tp.frontmatter.authors[1] %>]], ...

There are 2 problems that I don’t know how to solve.

  1. The number of authors is not always the same so I don’t want to list all the authors one by one using the <% tp.frontmatter %> method.
  2. If I use dataview to nicely list all the authors, I cannot add a link to their notes inside the Authors/ folder
    LIST file.frontmatter.authors
    WHERE file.path = this.file.path ```

Do you know a way to do that?

1 Like

The most “obvious” solution is: if you want the authors as links you can write them in frontmatter as links:

  - "[[author 1]]"
  - "[[author 2]]"
  - "[[author 3]]"

If not, you can add a link() function in the query

LIST link(file.frontmatter.authors)
WHERE file.path = this.file.path


LIST link(authors)
WHERE file.path = this.file.path

Links don’t work in frontmatter though. Do they?

They work if you use the right syntax: using quotation marks.
The only downside is: they don’t work as links in the main content, i.e., they don’t auto-update if you change the name…

1 Like

Got it.

Dataview can use frontmatter links with quotes but they are not updated and what we normally use as [[links]].

Apologies :sweat_smile:

1 Like

Apologies not accepted (because there’s no reason to apologies) :slight_smile:

1 Like

Thanks this is exactly what I was looking for. I wan’t aware of the existence of link().

I have noticed right now that this solution creates a link for ‘aut1’ (in my case) that is usually a non-existent note. But this note is made directly in the main folder of the vault.
I want it to be created always in the “Authors/” folder.
Is there a way to add this information to the link() function?

Hmm… That is a default obsidian behavior.
Let’s see if this “tricky” way works:

LIST map(authors, (a) => link("Authors/" + a, a))
WHERE file.path = this.file.path

Ok this works, Thanks a lot!
For anyone else curious about this solution, here you can find the definitions of the functions

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.