Creating an enum for YAML frontmatter

What I’m trying to do

I want to create an enum for my YAML frontmatter for a certain property to only accept specific strings such as:

exerciseType: ‘snowboarding’ | ‘climbing’ | ‘running’

and hopefully throw an error of some kind within the note itself if something not recognized is found, for example if I just put “run” or “skiing” in.

Alternatively if I can’t define a schema, it would be nice to have an on-hover popup for the schema instead. In the interem I’ve used just a comment with the accepted values above it, but the frontmatter section is getting very large with all these comments so I’m looking to make it a bit leaner.

Things I have tried

I’ve looked through the YAML docs and didn’t see anything about this so I’m imagining it might require some extra plugin or javascript to detect it.

I’m trying to have clean data for querying with the Tracker plugin. I’ve considered looking into something on that end when querying to display the anomalies but would prefer a system to catch the errors at the source.

I can think of three different approaches to this:

  1. Obsidian in the most recent version will when entering a value into a given property autocomplete the answers. If you define your answers somewhere in your vault for a property, it’ll kind of work as a lookup list. No error messages will be given if a non-legal value is used

  2. Using a plugin like Metadata menu (or possibly also metabind) would allow you to define properties to be tracked by them, and one option could then to say that this property is to be chosen from a given set. I think they might warn you on non-legal values, but not as errors

  3. Using a plugin like Dataview it’s relatively easy to query for all values of a property, and present to you which have been used anywhere in your vault. This can also be adapted to ignoring some values (aka those which are correct), so that it’ll only show misbehaving property values. Still not an error message, but it’ll at least show you which are incorrect when you execute the query

Thanks, the autocomplete solution will suffice for now!

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