Things I have tried

testing

What I’m trying to do

sort by tag

took a break from dataview, but now going back, I’m a bit confused about something. I thought that when I choose what tags i want to see notes from, e.g.

TABLE Name, Birthplace, Years, Tag
FROM #cat/history 
SORT Name DESC

that the tags had to be in the YAML section, but experimenting, I’m seeing that it doesn’t seem to matter whether the tag is in YAML or the body of the note. I would prefer the body of the note. Before I take them out of YAML, wanted to be sure that I’m not missing something or would have some loss of functionality in another unforseen case.

Also, seems there is some standard YAML tag formatting, but also testing, seems multiple things work. eg. w/ and w/o brackets, w/ and w/o quotes, commas, etc.

Is there a definitive way to write tags?

e.g.

Tags: [" #note/type/markup #note/source/blog-newsletter #note/source/mia #topic/american-politics "] (sometimes I dont have the bracket, and sometimes I have commas in there)

Tag:

  • " #note/type/markup"
  • " #note/source/blog-newsletter"
  • " #topic/american-politics"

Hi romebot! No, Obsidian permits tags both in the YAML (e.g. tags: todo) and in the body (e.g. #todo). Both methods work fine, and which you use is up to your personal preference. Dataview can see tags in either place too.

There is a subtle nuance as to the placement of tags depending your usage and patience. If placed inline, that particular block of text around the tag shows up in search results instead of just a barren tag, at the top of the note or above or below the associated block. I find, in my usage, that if a note is atomic like, a tag works ok at the top. If a note is large with many different disparate blocks of text, it reduces search friction to place the tag inline (actually I like to put them at the end of a block).

thanks so much! couple followup q’s: does it matter if you write tag or tags? and what about the various formats I described w/ and w/o quotes, commas, and bracket?

cheers!

thanks! could you expound on that maybe w/ an example… seems like it might be relevant to what I’m doing, but can’t visualize what you mean. best,

R

p.s. did it used to be different? I feel like I remember reading that for dataview to work it had to be in YAML. So I was putting it in both places so I could use the normal tag functionality. I’m happy to hear I can just use them in the body however!

Yeah, great question. It has to be valid YAML or else the frontmatter won’t parse properly. But apart from that Obsidian is very forgiving. The following all work for me:

tag: one, two, three
tags: one, two, three
tags: ["#one", "#two", "#three"]
tags:
- one
- two
- three

A rule of thumb: Don’t to use the # symbol in the metadata unless you enclose the tag in quotes.

I’m not certain. I seem to remember in the early days of Dataview it was only able to see fields in the YAML frontmatter, but soon after inline fields became available (e.g. Fieldname:: Value). But I think maybe tags always worked with Dataview no matter where they were in the doc? That’s my best guess. :slight_smile:

Yes, @Craig is right. If valid tags for Obsidian, then valid tags for Dataview (anywhere).