Help with YAML fields and Dataview

According to Obsidian Hep I should be able to create a field in the Frontmatter with a list of values beneath it as so:

key4:

  • four
  • five
  • six

However, when I try and query that value with Dataview it doesn’t work.

TABLE
	file.name as "File"
	WHERE key4 = "four"

The same goes for:

key4: [four, five, six]

However if I change the Frontmatter to:

key4: four

This works.

What am I doing wrong?

1 Like

Can u share the yaml in editor mode? Coz yaml formatting is a bit strict with spacing. E.g.

A YAML file use spaces as indentation, you can use 2 or 4 spaces for indentation, but no tab

1 Like

You’re trying to compare an array of values with a single item, and that is why no results are returned.

The following should work for you:

```dataview
TABLE
	file.name as "File"
WHERE
	contains(key4, "four")
```

This will work even if you have

---
key4: "four"
---

While technically not an array, it looks like dataview is treating it as an array for the purposes of the contains() method.

3 Likes

Thanks,

It’s confusing as all the Youtube video I watched about this never used “contains.” They did it the way I was trying and it worked for them. Perhaps they were old video??

Thanks again.

I have changed the code to use the “contains” function as suggested below so I don’t have the code. I did try tab indent, 1 space, 2 spaces, etc. But nothing worked.

And now … the “contains” function that was working yesterday was not working this morning. !?!

For example,
contains(key4, “four”) gives an error after the comma between “key4” and “four” where it didn’t yesterday.

I have made sure I’m using the latest version of Obsidian and Dataview.

Actually, I may have stumbled onto the culprit.

If I edit the code using my iPad and keyboard case it inserts instead of ". It’s a subtle difference that I had not noticed until now. When I changed it it works.

Is it possible the “space bar” on the keyboard case is different as well?
When I get home I’ll try the other method again and see if that was the problem.

I don’t actively use yaml in obsidian except for single alias. My experience come from setting up linux docker yaml. The guide always say to use space bar spacing for indenting due to different code editor interpretation of tab indent.

Maybe I’ll try it out later as well in obsidian. Been thinking about setting up some structured metadata fields

1 Like

After playing around on my iPad and iPhone I’m pretty sure it was the " and mixup. I guess my eyesight is getting worse with age, and I hadn’t expected my iPad keyboard case to be different from my Mac keyboard.

It’s working that way I originally tried it, and the way dugdun taught me. I actually like his method so I’m going to adopt that (thanks dugdun).

1 Like

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