How to write a dataview query using YAML fields?

What I’m trying to do

I am trying to write a dataview query that returns notes that have a certain date a yaml list field, like so:

---
edits: [2023-11-04]
---

Things I have tried

```dataview 
table without id
WHERE contains(edits, "2023-11-04")
```

It does not return the file (which definitely exists).

Strangely, if I change the yaml header to a dataview field like so:

---
edits:: [2023-11-04]
---

then the above query works.

The Dataview documentation states that YAML fields will are automatically made available as dataview fields. What am I missing?

The fence around the frontmatter needs to be triple-dash, ---. Then a field requires only one colon.

Otherwise it’s just ordinary text, and dataview will recognise inline fields with double colons.

Of course. That’s what I have. It was some kind of copy/paste artefact in my post. I fixed it.

Yes, that’s the point. A YAML field requires only one colon. And dataview supposedly recognizes these as fields that can be queried. But if I use only one colon, the query returns nothing. It only works if I add a second colon.

1 Like

If you need to use double colons, then most likely your frontmatter is not actually at the front of the file. Is there perhaps a line shift in front of the first triple-dash?

How do your frontmatter look like? Does it show the properties correctly when in reading mode ?

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