Best practice for storing page metadata

I suspect like a lot of other Obsidian users, I have created templates for my various page types, and each of those templates has a section for metadata. I tried use YAML front matter for storing metadata, and that appears to only partially work. In particular, tags in YAML do not appear to be processed like tags in the body of the page, and they don’t appear in the tag browser.

Here’s my question:

Is there a plan to extend the use of the YAML front matter to include a more general solution for storing metadata?

2 Likes

I’m using YAML myself…

Note that on your tags issue, tags have to be implemented differently in YAML as in the body.

In YAML it seems it’s:

---
tags: test_tag
---

or (if multiple tags):

---
tags:
- tag_one
- tag_two
---

These seem to work in my system.

Note you can NOT have the # (hash) at the start of the word… that is apparently invalid in YAML and doesn’t work. I expect that’s where you are encountering problems (I speak from experience, having just found this in the last few days)

I’ve see it several different ways now. All of the below methods seem to work, so I’d like to know the canonical syntax?

one

tags: foo bar baz

two

tags: [ foo bar baz ]

three

tags: [ foo, bar, baz ]

The proper Yaml syntax for a list of tags would be either:

tags: ['#tag_one', '#tag_two']

or

tags: 
- '#tag_one'
- '#tag_two'

The quotes are necessary because # has a special meaning in Yaml as the start of a comment, as @bdillahu already noticed.

However, Obsidian (in recent versions) does two things to make this less cumbersome:

  1. It adds the # automatically, so you don’t need to specify it, and then you don’t need the quotes either.
  2. If you don’t specify a list in Yaml, then a single Yaml value is split automatically using blanks and/or commas as separator.

So, utilizing these two features of Obsidian, you can just write:

tags: tag_one tag_two

The only small problem is that Obsidian (currently) still doesn’t show suggestions while typing the tags that way. As a workaround, you can add the tags with a starting # so that Obsidian suggest possible tag names and then remove the ‘#’ again to make it proper Yaml syntax. If there is a Yaml syntax error, then Obsidian will not read the frontmatter.

1 Like

Thanks @Cito - yes right now I use a template for my YAML frontmatter that uses the tags: [ #xxx #yyy #zzz ] format. This way I can get the tag autocompletion.

My workaround is an Alfred script that strips the #s when I’m done so they become valid.

Hopefully one day Obsidian will support autocomplete in the YAML area without the hashtags.

1 Like

If you want to have a strict Yaml syntax, then you need to use square brackets and separation by commas. If you want to rely on Obsidian for splitting tags, then you can remove both the square brackets and the commas.

Your notation without commas is a kind of mix. It looks like Yaml, but it is only a single list entry and still relies on Obsidian magic to split it up.

1 Like