Hey everybody,
I am trying to define a key with a list of values in yaml front matter (or in-line, see below), and then use dataview to make a list (or table or whatever) of all files that contain one specific value in that list. e.g.:
the front matter bit:
---
type: book
copy:
- library1
- library2
- personal
---
and the dataview query:
```dataview
LIST
FROM "books"
WHERE copy = "library2"
```
somehow, dataview and/or yaml don’t seem to accept the lists I define. If I use only one value, it works fine. as you can probably guess, I organize my literature with obsidian and I want to note in which libraries I can find a particular book and then generate lists for each library so I can see what to get on my library visits.
what I’d like even better would be using standard obsidian tags instead of front matter, cause the former offer auto-complete, so I don’t have to remember all the shorthands for the libraries. Is there a any way to achieve this?
Things I tried
I also tried to define the lists with square bracket, without brackets just separated by commas and inline key-value pairs (key:: library1 library2 etc).
It would be so cool if anyone could point me in the right direction to make this work. Thanks!
---
type: book
copy:
- library1
- library2
- personal
---
Dataview query
If you want to filter one of the array elements, you need to use the function contains(field, "value") (you can use copy = "library2" if you have only one value, not a list/array).
Try this query:
```dataview
LIST
FROM "books"
WHERE contains(copy, "library2")
```
Using tags
If, instead of frontmatter values, you prefer using tags (#library1, #library2, …) anywhere in your file, you can use for the query the implicit field file.tags… or, more simple, define tag as the source (FROM #tag).
Try this query
```dataview
LIST
FROM #library2
```
EDIT: You can use multiple source filters. So, if you want keep the filter to folder “books” just compose the source filter with the expression FROM "books" AND #library2
For Dataview plugin in particular, following the advice from some ‘code experts’, it’s more advisable to use the two spaces (because “YAML is an indentation-based markup language”).