Allow links in YAML front matter; Notion-like databases from metadata; links as first-class citizens

First, I’d like to thank all contributors to Obsidian for making the absolute best knowledge management application!

Over the years many applications never quite delivered what I was looking for and ideas of a better system started accumulating in my mind. The most notable idea being able to link anything to anything and use those links as tags themselves. Notion almost made this possible, but not completely. Then Obsidian appeared, turning this dream into a possibility!

As I’ve become acquainted with Obsidian I’ve realized that many of my notes are of a particular type or kind. Let’s use Movie for example. For any note that’s a movie I can just add a [[Movie]] link to the top of my file and BAM, that link itself serves as a tag for all movies.

However, all notes that have an “is a” relationship to movie also happen to share a standard set a metadata such as director, run time, IMDB rating, etc. The obvious solution would be to create a template for Movie that I can apply to all “is a Movie” notes. This does begin to solve the problem of keeping all of the metadata standardized, but as you will see some problems still remain.

My next thought was for this metadata to be parsable in a way that I or someone else could build a plugin to view all notes that are a movie in a table just like a Notion database with a standard set of properties. Then I found YAML support for Obsidian which seemed perfect! That is until I realized links do not yet work in YAML front matter. Therefore links could not serve as the metadata values to be used by plugins.

Having the metadata with links for a movie note would look something like the following:

---
is a: [[Movie]]
director: [[Ridley Scott]]
run time: 2hr
IMDB rating: 7.8
---

Such metadata formatting would allow plugins to be built that create Notion-like database views (table, cards, kanban) and at the same time maintain a rich backlink ecosystem. The last thing I want to have to do is add duplicate metadata in YAML and my own block below it.

I’m certainly not the only one that uses links as tags. It seems to be quite a popular trend. Another popular trend for many users seems to be adding links to the top of their notes as metadata that’s nearly identical to YAML front matter. This is a very common pattern. Also notice that this pattern is already very similar to the pattern of Notion Page properties. Perhaps we see some standard design patterns emerging for knowledge management systems.

TLDR

I deeply desire the option for YAML metadata to be universally link compatible. I want to build, or see built, plugins that can take advantage of YAML metadata that are also links, while at the same time Obsidian also observes them as links in the graph.

I propose that the syntax could be something like the following and just use the standard link formatting already used:

---
customProperty01: [notalink, randomstring]
customProperty02: [[[isalink]], [[another link]]]
customProperty03:
- notalink
- [[isalink]]
links: [NoteB, NoteC] <-- Similar to "tags", but creates links.
---

Related feature requests (optional)

23 Likes

I am copy/edit here where we stand currently from the archived thread. Then, I’ll add some remarks.

You can add your custom attributes in the YAML frontmatter but:

  • They MUST be in proper yaml format.

  • If an attribute is not handled by obsidian or plugin, it will be ignored. But still has to be YAML format.

  • The YAML frontmatter is not scanned when searching for unlinked mentions (and probably never will be). That is, if NoteA has this frontmatter:

---
connections: [NoteB, NoteC]
---

NoteA will not appear as an unlinked mention in NoteB and NoteC.

  • There is no support (yet) for adding a linked mention to another note, that is, if NoteA has this frontmatter:
---
links: [[[NoteB]], [[NoteC]]]
---

It will not work. NoteA will not appear as a linked mention (backlink) in NoteB and NoteC.

If at some point we add support for linking other notes in the YAML block, it will be specific and limited to a YAML attribute, like related: . But it still won’t be possible to add linked mentions in other attributes.

Remarks

Thare is an interesting dichotomy between the YAML block and the rest of the text.
The YAML block is meant for database-like approach: highly structured data that is handled by specialized software.
Obsidian, and tools like it, were born under the idea of using unstructured plain text data (or not so structured) and rely exclusively on connections and search/filters.

You can solve many productivity problems using either approach. Some workflows look cleaner with one or the other.

Now back to your proposal, you can either 1) write a plugin to explicitly handle your movie data or put it in the main text, perhaps in block right after the YAML block, and rely on Obsidian linking engine.

---
# YAML BLOCK
---
# Your Block
___

(Edited Example)

5 Likes

IMHO the proposal of having another block after the YAML front matter block is just a bandage on top of the problem and not a real first principles solution. Problems that are addressed by applying bandages just create compounded problems in the future.

If YAML front matter is intended to serve as the metadata for a note, then we shouldn’t have to resort to other methods to add metadata because of some incompatibility. Resorting to a second block below YAML will cause that metadata not to work with other plugins because it is no longer part of a standard. I absolutely want any and all metadata that I add to every note to work with any plugin regardless if the metadata values are links or not.

Additionally, if backlinks are a core feature and value proposition of Obsidian, then they should be first-class citizens in order to maintain flexibility and give more power to the user. That’s what I love about Obsidian, it’s extremely flexible with just the right amount of structure that allows for that flexibility.

It seems that a very simple solution would be a setting to let the user choose if Obsidian recognizes backlinks within YAML. Also, I personally don’t care to have Unlinked mentions recognized from YAML, but perhaps this should also be configurable and up to the user.

I do understand that the backlink syntax might cause some unforeseen issues with YAML syntax, but this seems easily resolved by wrapping all YAML backlink values in quotes. Maybe I am ignorant of other issues and reasons for not wanting to support backlinks in YAML and would love to hear more thoughts on the matter.

5 Likes

I hope Folder View like a table of front matter contents.

for example:

| note name | aliases | tags | updated time |
| --- | --- | --- | --- |
| [[noteA]] | alias-a1, alias-a2 | tag-a1 | 2020-12-17 13:27 |
| [[noteB]] | alias-b1 | tag-b1, tag-b2 | 2020-12-17 13:40 |
| [[noteC]] | alias-c1, alias-c2, alias-c3 | tag-c1 | 2020-12-17 13:50 |
| [[noteD]] | alias-d1, alias-ad | tag-d1 | 2020-12-15 13:10 |
2 Likes

YAML stands literally for YAML Ain’t Markup Language, and just that says a lot about this topic.

As you can read in its specification, YAML is based on three basic primitives:

  • Mappings (hashes/dictionaries).
  • Sequences (arrays/lists).
  • Scalars (strings/numbers).

Everything that doesn’t respect this premise will potentially break most of YAML parsers, and even though this might be implemented, it will definitely break compatibility with other programs.

Apart from that, a related tag can be useful in some specific use cases, +1

(1.) @pyrotecx What do you mean by

backlink formatting already used

and/or

backlink syntax

?

( In Obsidian pane which shows backlinks for current note, I see just quotations/transclusions of pieces of text that contains filename of current note. Either inside link markup [[]] or []() for linked mentions or outside / anywhere else for unlinked mentions. )


(2). Links in YAML were also discussed in thread about support for link types:

Are we able to add our own YAML block after the first YAML front matter block like you mention here…

@WhiteNoise said:

Now back to your proposal, you can either 1) write a plugin to explicitly handle your movie data or put it in the main text, perhaps in block right after the YAML block, and rely on Obsidian linking engine.

---
# YAML BLOCK
---
# Your Block
---

When I try this, Obsidian renders my block as an H2 header in both edit and preview mode. Not sure if this is a bug or intentional.

add a blank line or use another marker _ or +

1 Like

@malecjan, when I said

backlink formatting already used

and

backlink syntax

all I meant was the wiki style bracket syntax [[link]] that Obsidian already uses for links.

Also, thanks for the reference to Add support for link types. It inspired me to refine my original idea of including the [[link]] syntax within YAML. I think that including the bracketed [[link]] syntax within YAML is messy and unclean. Imagine a YAML sequence of links like so:

---
is a:        [[Movie]]
director:    [[Ridley Scott]]
run time:    2hr
IMDB rating: 7.8
genres:      [[[crime]], [[drama]], [[mystery]]] <-- fairly messy
---

This array of links within YAML could also be parsed as nested array’s containing a single item.

I think I much better approach that aligns with how @WhiteNoise said YAML link support will probably be added to Obsidian is to use a YAML anchor and alias like so:

---
is a:        &l1 Movie
director:    &l2 Ridley Scott
run time:        2hr
IMDB rating:     7.8
genres:      &l3 [crime, drama, mystery]
related:         [a link, another link, *l1, *l2, *l3] <-- Obsidian recognized links
---

The former YAML would be equivalent to the following YAML:

---
is a:        Movie
director:    Ridley Scott
run time:    2hr
IMDB rating: 7.8
genres:      [crime, drama, mystery]
related:     [a link, another link, Movie, Ridley Scott, crime, drama, mystery] <-- Obsidian recognized links
---

Additionally Obsidian should support a custom YAML tag such as !link. In the following example links would be parsed equivalently to the previous two examples.

---
is a:        !link Movie                   <-- Obsidian recognized link
director:    !link Ridley Scott            <-- Obsidian recognized link
run time:          2hr
IMDB rating:       7.8
genres:      !link [crime, drama, mystery] <-- Obsidian recognized link
related:           [a link, another link]  <-- Obsidian recognized links
---
5 Likes

Vote+1

2 Likes

Sorry @pyrotecx, I just want to clarify:

What is &l1? Is that a tagging feature already built into YAML?

If I understand correctly, under your proposed syntax Obsidian will only recognize a link if either:

  1. it’s included under related: or
  2. it has the YAML tag !link
    If neither or those conditions are met then it will just be metadata, but not an Obsidian recognized link?

Perhaps this might need to be a separate feature request, I’m not sure but:

What if each custom property like director: or genre: could optionally have it’s own Obsidian note automatically created. This could have the following benefits.

  1. When editing YAML front matter, Obsidian could suggest code completion for us.
    • For example: While typing gen, Obsidian could overlay a list of possible completions like genre: and general: etc.
    • Advantages of this approach:
      • Code completion helps us not make accidental duplicates when we misspell.
      • faster typing
      • we’re already familiar with code completion when we type [[ and Obsidian suggests notes for us
  2. When we add an attribute to director:, Obsidian could auto add backlinks.
    • For example:
      1. Obsidian could auto-add the Ridley Scott note as a “child” of the director note.
      2. Obsidian could auto add is a: director to the YAML front matter of the Ridley Scott note.

This way we can make simple changes in one place and have related changes propagate out to other places automatically.

2 Likes

This is great idea/workaround/solution for extending links into whole yaml front-matter when recognition of links in the field “related” is implemented. I would consider incorporating it into main post or at least point to post #9 from the main post.
Additionally, for readability in basic text-editors, we can use yaml comments to materialize text locally near YAML references.

---
is a: &Movie Movie
director: &l2 Ridley Scott
run time: 2hr 
IMDB rating: 7.8 
genres: &l3 [crime, drama, mystery]
related: 
  - a link
  - another link
  - *Movie
  - *l2 # Ridley Scott
  - *l3 # [crime, drama, mystery]
---
1 Like

@Fanshu , @luke85
To vote for the feature request, do not forget to press :heart: under original post, officially prefered method of voting according to FAQ:

Rather than posting
“+1” or “Agreed”,
use the Like button.


@DandyLyons Yes, these are yaml anchors and yaml custom types.

2 Likes

@pyrotecx
Thank you for clarification of what you mean when you say “backlink”.

  • When a page “P” contains [[A|Link to page A]], then From viewpoint of page “P” it is called just a “link”. It is called “backlink” only from viewpoint/perspective of the page “A”.
  • Obsidian is said to have “backlinks” functionality because it is able to show which pages do link to currently active page “A” (via “backlinks pane”).
  • I suggest to edit the original post to change relevant instances from “backlink” to “link”, to avoid confusion of readers (especially the novices) due to misuse of terms. I have encountered this confusion several times in recent times since introduction of Roam Research. I imagine how easily the self-strenghtening misuse of (now cool) term “backlink” can lead to messy discussions and consequently to the need for new word (e.g. “backbacklink”) in order to express/distinguish the original meaning from potentially new common interpretation of word “backlink”.
  • For example, part of the title will change to Allow links in YAML front matter; which explains the intention immediately without need to decrypt anything and so potentially attracts more votes from people who do not have time to read the whole post.

Edit: thank you for making the corrections.

4 Likes