Wikilinks in YAML front matter

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.

You are spot on. Let’s bring back the true intention and focus of this thread:

The most notable idea being able to link anything to anything and use those links as tags themselves.

I’d also like to remind everyone of a secondary point, which is the fragmentation that has occurred between plugins in how they handle custom front matter or key-values. Some choose to work with the non-standard key:: value syntax and some don’t.

Standards are essential for composability and that’s why YAML exists in the first place. Ever since the key:: value syntax hack for “your frontmatter” was established, plugins have become incompatible with one another.

I am highly interested in storing metadata for Note or metadata for some parts of note. It is necessary precondition for the features I need to have in Obsidian (or plugin). I am going to invest my development effort into that during next 2 months.

Therefore it is critical for me to have an inkling about the raw ideas/concepts you are discussing.

@WhiteNoise, Is it possible to see current state of ideas/concepts somewhere?
Do you plan to invite cool Obsidian community to discuss this stuff?

I would be interested to attend.

2 Likes

You might find this interesting:

datacore/ROADMAP.md at master · blacksmithgu/datacore · GitHub

2 Likes

There is ongoing work in v1.4 to restructure the YAML frontmatter to be used as note’s properties by users (not just plugins). There are many changes, one of which being the possibility to use wikilinks in all fields of type text and list.

Obsidian_6tIinoqznr

Obsidian_RnbwAmBF2U

17 Likes

:ribbon: :tada:
Yes and again yes and a thousand times yes

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