I have looked at the Templater and Dataview community plugins but not been able to do what I want.
What I’m trying to do
Aim
To retrieve a list of tags from specified files, e.g. in a folder, and insert them in files created from a template. Ideally this would be something that auto-updates when new tags are added.
Use case
I have a template file for an about/readme md file for each folder and, when it is created, I would like it to list all the tags from other files in that folder, either in the yaml section or as a list in the body of the note.
You can insert this query in your “readme_A” file:
```dataview
TABLE file.tags as tags
FROM "Folder_A"
WHERE file.name != this.file.name
This gives you a table/list of all the files in Folder_A, excluding the “readme_A” file (the expression WHERE file.name != this.file.name excludes the file where the query works - you can remove it if you want…).
Problem file.tags is an “implicit field”, that is, a file metadata that gives you all the normal tags you create in the body of the note. To the tags created via YAML depends how you created them.
Hi @mnvwvnm , thank you for your reply. It’s been rather hectic so I have only just come back to this.
Thank you, your code gives me a table of all the files, except the current one, and all the tags in each file. I have tested it and it works with inline tags and with tags in the yaml, e.g. tags: [‘tag1’,tag2’].
Do you know of a way to list just the tags (no file names) and without duplicates?
If you want a list of all your tags on a note then the following command would do ```dataview table file.tags ```
But if you want a list of, say, the notes containing #tag1, #tag2, #tag3 then you will have to use the following commands ```dataview table file.tags from #tag1 or #tag2 or #tag3 ```
In the second method you will have to replace “or” with “and” if you want only those notes which has all the three tags . For example, let there be three notes- Note1, Note2, Note3. These notes have the following tags-
Note1 = #tag1, #tag2
Note2 = #tag1, #tag2
Note3 = #tag1, #tag2, #tag3
Now if you use from #tag1 and #tag3 then only Note3 will be displayed since it satisfies both the criterion, whereas if you use from #tag1 or #tag3 then all the three notes - Note1, Note2, and Note3-will be displayed since each note fulfills either of the criteria
The code snippet below will get all tags without duplicates and filenames in a certain folder. Notice that you should replace <path> with the path to the folder instead of the folder name only.
```dataviewjs
let tags = []
for (let tag of dv.pages('<path>').file.tags) {
if (tags.indexOf(tag) == -1) {
tags.push(tag)
}
}
dv.list(tags)
ha this is epic and exactly what i was searching for!
in a related query, whats the best way to export these results to a text file and get rid of the # (hash) sign? is there a programatic way to do this with the dataview js script?
i need to update this tag list often for other apps
How can I use dataview to list all files that share at least one tag with the current (active) file? I’ve played around with this.file.tags but without any meaningful result so far…
Edit: Found the solution - for anyone interested:
table file.folder
Where contains(file.tags, this.file.tags[0])
sort file.path
the “dv.” code is the javascript version, if you stick to the basic dataview code instead, like at the top, you can easily add exclusions with “and” statements tacked onto the WHERE line.
This code is an unrelated query for file sizes but you can see the tag exclusion and the path exclusions I added.
```dataview
LIST
from “”
where length(file.inlinks) =0 and length(file.outlinks) = 0 and file.folder != “4. ARCHIVE” and file.folder != “4. ARCHIVE/TEMPLATES” and !contains(file.tags, “#io”) and file.folder != “001 DAILY” and file.folder != “001 DAILY/PAST”
```