Dataview : table from links within metadata

I hope this isn’t a duplicate but I have searched the forum for a bit and couldn’t find an answer.

What I’m trying to do

I have a folder named “Spells”, inside this folder there is a bunch of notes with several metafields (rank, path, description).

I want to be able to list the spells with dataview on a new note (let’s call this note “John”).

On the “John” note, I have a metafield

  - [[ Spell 1]]
  - [[ Spell 2]]
  - [[ Spell 3]]

Is there a simple way to display those spells with a dataview table inside the “John” note ?

What do you want to list? I mean, what is your search criteria? Do you want to list all notes from the folder “Spells”?

I want to list the spells listed inside the “spells” metafield.

That way I can simply add spells in this metafield (and have autocomplete to prevent errors) and have a beautiful dataview table below.

To explain in another way, I want the same result as

FROM outgoing([[]])

but the links are listed inside the “spells” metafield of the same note and not on the content of the note.

FROM "Spells"

If “Spells” is a subfolder, write the complete folder path.

I don’t understand what you mean… :thinking:

This is the frontmatter of the “John” note :

  - [[Spell 1]]
  - [[Spell 2]]
  - [[Spell 3]]

So if I understand correctly, you are writing your links into a frontmatter field in order to hide them from your note content, and then you want to write a dataview query in order to see them again in your note? :thinking:

Exactly :smile:

But the idea is to display them as a table with dataview

Do you want them to display as clickable links?

Ideally yes, but the most important thing is to display other information in the table (rank, description, etc.).

OK, we are slowly approaching an understanding of what you are looking for: you want a table where the first column shows, for example, “Spell 1”, and the second/third/ etc. columns show the content of “rank” and “description” from the file Spell 1?

Exactly, sorry for the chaotic explanation.

The layout of the result isn’t that important, the main problem is to be able to use a list from within a metafield as a source for the dataview table.

As far as I know wikilinks in frontmatter are not yet supported by obsidian - so I guess they cannot be read by dataview as outlinks. Possibly some regex in the dataview query could achieve the desired result…

Why don’t you put your outlinks into a comment? (%%[[YourLink]]%%)? Then they aren’t visible on your note in reading view but can easily be searched by dataview:

TABLE rank, description
FROM outgoing([[]])
1 Like

I didn’t think to use comments in that way, that’s a good idea.

That’s not perfect but it’ll do the trick :wink:

1 Like

There are some other alternatives too, so try putting the stuff below into a file and check out which version you like:

Tags: f61088
- "[[spell 1]]"
- "[[spell 2]]"
- spell 1
- spell 2

## Proof of Concept
TABLE WITHOUT ID quotedLinks, link(namedLinks)
WHERE file.path = this.file.path

## Using quotedLinks
TABLE WITHOUT ID qLink as Spell, qLink.type, qLink.rank
FLATTEN quotedLinks as qLink
WHERE file.path = this.file.path

## Using namedLinks
TABLE WITHOUT ID nLink as Spell, nLink.type, nLink.rank
FLATTEN map(namedLinks, (l) => link(l)) as nLink

WHERE file.path = this.file.path

This assumes there to be a “spell 1” and “spell 2” note somewhere in your vault, but other than that it shows two variants of having something resembling links in the frontmatter. I say resembling, as neither of these will show up in backlinks or graph views, and they’ll not be renamed if you rename the spell notes. They also vary a little in handling, and how they appear in reading view.

I am was not sure how the comment variants presented by @alltagsverstand will operate related to the same issues, so you need to test it out, and consider what matters the most to you. Update: It seems like even though in comments, Obsidian will still treat them as ordinary links, so they’ll show up in backlinks, graph views, and be renamed, and so on.


@holroy This is very interesting - so dataview can follow links that are not even treated as links by obsidian and read the respective files’ contents… Didn’t know that (in fact, never came up with the idea to try it out… :wink: ).


Thanks a lot @holroy , that’s exactly what I was looking for.

And thanks again @alltagsverstand I appreciate the time you took to help me.

1 Like

But (just in case you didn’t realize) be aware that

Especially in the latter case (if you ever would rename, for example, “Spell1” to “Spellxyz”), your link as well as your dataview table will be broken and it will be difficult to reconstruct which connection you had established originally!

1 Like

To combine the two to get the best out of it, you could also consider doing this variant:

TABLE WITHOUT ID spell, spell.type, spell.rank
FLATTEN spells as spell
WHERE file.path = this.file.path

spells:: [[spell 1]]
spells:: [[spell 2]]

Notice how we’re using multiple lines of setting the inline field, spells, to make it into a nice list of values. This could also be shown other places in the text, either as [spells:: [[spell 3]]] or my favorite with a hidden key name, like (spells: [[spell 4]]). The latter allows for stuff like:

After you complete [[The earthly challenge]], you gain access to the (spells:: [[Earth spell]]), which allows you to use earth for something.

Which you could style to whatever, but with my current theme settings shows as:

Note that one could think about using markdown lists within the comment section, but file.lists doesn’t include lists within comment sections, so then one would have to make the list show in the note. The alternatives above is kind of a mix allowing for it to behave like a list of spells, while one maintains the “normal” link behavior.


@holroy After @mnvwvnm obviously disappeared from actively following this forum, you definitely have become the new dataview guru! :slightly_smiling_face: :+1: :pray:

Btw (even if I mess up this thread with a different topic): for a couple of weeks now, hidden key names don’t work anymore for me - as a result, both the key and its value are completely hidden! :thinking:

Edit: Just found out myself - for a reason I no longer remember I suppressed the appearance of inline fields via css… :roll_eyes: