Wikilinks in YAML front matter

FYI:

And Licat’s answer specifically:

We have no plans to implement Notion/Airtable-like database functionalities, but that in theory doesn’t prevent plugin authors from turning Markdown tables into databases […] This is the trade-off we made for Obsidian, which is why I said I don’t think this would be changed at all. It’s in Obsidian’s DNA. Of course, it’s entirely up to you whether you want to make that trade-off, and we respect that. If you value functionality more than future-proofness, something like Notion or Fibery might work better.

1 Like

I wanted to use front matter for metadata, but found you could not include links to other notes in the YAML. I was okay with that as long as I could create a link within my document using the front matter data value; however, I had difficulty finding a way to create a dynamic link to another note.

I finally found out how to construct this type of link and hope this will help others.

Here’s a simple example for a D&D character. The character race is indicated as “Human” in the front matter, and I want to create a link to the “Human.md” note.

image

This will create the text “Character Race: Human” where the word “Human” is a link to the file “Human.md” as you see below.

image

Apologies for embedding images, but I don’t know how to post text without having it reformatted and some of the details lost. Make sure to include a “`” at the beginning and end of the expression. This is the non-shifted version of the “~” key.

Dataview is the only community plugin I have enabled. I don’t believe it is required for this to work, but if you have any issues you might consider enabling Dataview.

This allows me to accomplish what I wanted to do and still use front matter instead of inline metadata link assignment (E.g. “race:: [[Human]]”) somewhere else in the document. This might seem obvious to many of you, but I hope it will help others like me that are new to this.

If anyone knows a simpler or better approach, please let me know.

1 Like

Unfortunately, this construction works as intended only if you use one-word values. With value like “High Elf” it will work only if you replace the space with “%20”, but now there is a stylistic problem — your link looks like “High%20Elf”. Of course, you can create a second field for a “clean” title, but that’s bodging on top of bodging. Still, for simple tasks it is a good solution.

That probably requires DataView — it doesn’t look like default Obsidian functionality.

To post code without losing its formatting, mark it as code: Format your notes - Obsidian Help

For showing Live Preview/Reading Mode formatting, pictures are the way to go.

You can preserve spaces in Markdown links by wrapping the URL/path in angle brackets:

="[" + this.race + "](" + "<"this.race">" + " md)"

Or you can use wiki links instead:

="[[" + this.race + "]]"

I don’t use DataView so I may have garbled the syntax, but the link formatting ideas should work when you have the right syntax to apply them.

1 Like

The Lila’s frontmatter :cherry_blossom:

Hi there !
I’ve just published a topic about my current frontmatter solution, which allows :

  • links to be :
    • auto-completed while typing
    • clicked in both Editing and Reading modes
    • reflected in the graph view
  • frontmatter to be :
    • easily editable and readable in Editing mode
    • else hidden, folded or entirely visible in Reading mode
    • properly readable in other Markdown editors
Theme
Dark Peek 2023-01-25 12-45
Light Peek 2023-01-25 12-42

:arrow_forward: You can find the full details here

3 Likes

I wanted to share another approach to have a frontmatter with wikilinks. I make use of a hidden text block, that is in between %%.

In addition to that I make use of the plugin Dataview and that is all.

The top of a note could look like this, and could be a used in a template:

%%
created:: 2023-01-26
updated:: 2023-01-26
type:: [[Research]]
rating:: 3
parents:: [[Parent1]], [[Parent2]]
%%

`=[[Dataview]].frontmatter1`

## Abstract

The line =[[Dataview]].frontmatter1 determines how the data will be shown in reading mode.

In the note “Dataview” I have defined how I want the data to appear in all my other notes. This way I only have to change 1 file to change appearance in all my notes.

I made 3 examples in the note “Dataview”:

frontmatter1:: Type: `=this.type`<br>Rating: `=this.rating`<br>Updated: `=this.updated`<br>Created: `=this.created`<br>Parents: `=link(this.parents)`

frontmatter2:: Type: `=this.type` • Rating: `=this.rating` • Updated: `=this.updated` • Created: `=this.created` • Parents: `=link(this.parents)`

frontmatter3:: Type: `=this.type`<br>Rating: `=this.rating`<br>Parents: `=link(this.parents)`<br>Updated: `=this.updated`<br>Created: `=this.created`<br><br>Folder: `=this.file.folder`<br><br>Inlinks: `=this.file.inlinks`<br><br>Outlinks: `=this.file.outlinks`

In reading view it looks like this:

Example1:
image

Example2:
image

Example3:

Hopefully it is useful for someone.

9 Likes

This is super useful. I didn’t realize you could create template fields in another page, then use an inline field to evaluate them in the context of the current page! This means we can create some kinds of Dataview templates without needing to use dv.execute(await dv.io.load(...)).

An awesome tool for the toolbelt. Thanks for sharing!

1 Like

I’m glad you find it useful!

Another thing you could also find handy is this functionality with Dataview.

In a note “Dataview” you can also define things like this:

ratings::☆☆☆☆☆%★☆☆☆☆%★★☆☆☆%★★★☆☆%★★★★☆%★★★★★

and in the context in your other notes you can use that to show stars instead of numbers:

=split([[Dataview]].ratings, "%")[this.rating]

So instead of displaying this:

you can display it like this:

To take it one step further, you can also use html in the string in the “Dataview” note.

ratings:: <font class="note-rating">☆☆☆☆☆</font>%<font class="note-rating">★☆☆☆☆</font>%<font class="note-rating">★★☆☆☆</font>%<font class="note-rating">★★★☆☆</font>%<font class="note-rating">★★★★☆</font>%<font class="note-rating">★★★★★</font>

In css you can define the colors like this:

.note-rating{
	color: #ffff00;
}

This looks like this:

with this code in the note “Dataview”:

frontmatter1:: Type: `=this.type`<br>Rating: `=split([[Dataview]].ratings, "%")[this.rating]`<br>Updated: `=this.updated`<br>Created: `=this.created`<br>Parents: `=link(this.parents)`
6 Likes

That is totally brilliant!

1 Like

Use case or problem

When I add a date the YAML frontmatter in a note, I want the daily note (titled with that date) to display this note as an Unlinked Mention.

This improves my ability to explore my vault by simply browsing my daily notes, and seeing other notes made on those days through the Unlinked Mentions panel.

Proposed solution

Make unlinked mentions work the same as regular full-text searches, including YAML frontmatter.
(Maybe it doesn’t work this way for a reason. Feel free to let me know)

Current workaround (optional)

Perform full-text searches for dates to explore notes made on that day

Hi @ketchup
You may find this plugin handy GitHub - franciskafieh/obsidian-list-modified: 🪨 A simple obsidian plugin that links all modified files meeting certain criteria to a daily note

1 Like

Hi there,
I have been looking for a solution to this problem for a while, and invested the last 2 days to read through all related work I could find. I tested what I could come up with, and composed everything (Including the very neat solutions by @JayKim and @LilaRest) into one post:

I think we might have a workable solution in reach. @WhiteNoise stated many times that YAML is not to be touched, and with one or two tweaks maybe we don’t have to:
With @JayKim 's solution we have something like:

%%
created:: 2023-01-26
name:: [[Peter Parker]]
parents:: [[Parent1]], [[Parent2]]
%%

`=this.name` is a ...

Where now every information can be stored in one place, used throughout the page and be picked up by dataview, obsidian and humans alike.

3 Likes

Sorry, would you mind sharing some details about what you mean that about “YAML is not to be touched”? Does that mean we should eschew using YAML front-matter for adding our own metadata?

I also remember reading that DataView 2.0 (i.e., “Datacore”) is moving away from inline metadata) …

@jeetsukumaran I was refering to statements like this:

We can use YAML for the purpose YAML was intended for, but can’t stach all other features we want into the same field. So we have two blocks:

YAML

%%
Fancy feature space
%%
Merging those two has +5 to convenience, but -10 to consistency.

At least that’s how I interpreted it, and with building like that the past few days, it worked well enough for me. I barely use YAML nowadays, since most what I wanted to do was part of fancy feature space, for which I “abused” YAML.

3 Likes

I wanna add a quick comment here that an overhaul of the YAML frontmatter, its scope, and its UI-UX is on the roadmap.

It may impact this feature request.

Don’t ask me what and when because ideas and code aren’t finalized yet.

8 Likes

Thanks.

So we have " the purpose YAML was intended for", which is " per file settings/data of plugins ".

Does that mean that we should not use YAML for any metadata that is not related to plugins? Would data specifying pandoc compile systems or lists of directories with resources outside the vault be abusive? Because it’s not “content” either. Either way, I’ve started a thread on this to get more information: Mar 2023: Current "Vision" For Userspace Metadata: YAML? Frontmatter? Dataview Inline?

Thanks @BorgNetzWerk to bring this topic under attention again. Would be great if it will be reworked in the (near) future.

Keeping the standard syntax for frontmatter is important to keep the files compatible with other editors.

How I could see it work is having an alternative frontmatter allowed in obsidian (obsidian specific) that handles wikilinks and tags the same way as in the rest of the note. In addition to this there should be an option/toggle in the editor to convert from standard frontmatter to the obsidian specific version. I think to make that possible there should be some conventions/rules added to that new frontmatter to make it possible to switch between those two. It also would be great to be able to fold/unfold it like the feature that @LilaRest made.

That is just how I see it work, but probably there are other ways to accomplish this.

3 Likes

This could be great news! I’m back after a very long hiatus hoping that Obsidian would evolve into something capable of using atomic notes for everything with links as first class citizens, and it’s almost there!

There are a ton of new plugins providing more Notion-like features which is extremely exciting. Especially since Notion becomes more and more buggy and still has no offline mode! I’m also an advocate for the ownership of personal data and have been working on a web3 startup to make self-custody of tokens and data easy for the everyone, unlocking a new paradigm where apps connect to you and not the other way around.

I’d like to plea once again for links to have first class citizen support within Obsidian and support for them in front matter. Some plugins support the key:: value format, but it looks like many still only support front matter (forgive me if I am mistaken here), causing incompatibility and a bifurcation of standards. In my opinion, this was simply a side effect of the community being forced to find a work-around for their YAML needs. For example, it may have been more appropriate to define in YAML itself which of the YAML keys should be show in read view instead of the key:: value work-around.

There seems to be quite a lot of demand for my original proposal. I’d love to jump on a call with you @WhiteNoise and discuss the possibilities of simple and compatible solutions. There are lots of great solutions proposed within this thread and I’m hopeful a simple and elegant solution will be implemented.

YAML syntax for indentation is too much rigid.

But while editing some text in that suppose we can configure a custom parser.
This will uses some features of the language.

Adding some semantic to the text makes it better for editors not developers.

I think this could be one way to implement this better.

TL;DR
We can determine the syntax and semantics for editing, or some variations to do author feel free.
The parser we constructing on the way.