Hello!
Currently new-ish to obsidian but I am picking it up quickly after switching from OneNote and I am attempting to setup an environment for my DND note usage.
What I am trying to do here and what I want to be able to do is pull NPC “locations” from their folder names (which are locations in my DND setting), essentially all I have to do is drag and drop NPC’s to the respective folder of where they are in my setting as that’s easier than editing.
What I’d like to do with Dataview is have a table set up to where the entries read the folder it’s in as part of the TABLE , rather than using FROM on a specific folder.
That way, I have a list of all tagged NPC’s without having to change internal data and can simply just move them from one “Location” folder to another “Location” folder. Essentially all it needing to take is list it’s parent folder somehow in Dataview.
Is this possible at all? Are there better ways to do this?
Try with regexreplace(file.folder, ".*\/([^\/]+)$", "$1") instead of file.folder. It’s using regex to remove the other parts of the folder structure. It’s kind of greek to many, but it should do the job.
If you show the entire query, someone could possibly also beautify all of it, so it looks a little nicer.
TABLE regexreplace(file.folder, ".*\/([^\/]+)$", "$1")
FROM #NPC
At the moment but I am experimenting and was just trying to find a nice and clean to be able to index things better and essentially have all my NPC’s listed and where they were at. Not sure what else could be good tables to call for ease, havent set up too many tags in my templates yet.
```dataview
TABLE WITHOUT ID file.link as NPC, Location
FROM #NPC
FLATTEN regexreplace(file.folder, ".*\/([^\/]+)$", "$1") as Location
SORT Location
```
This shows some interesting concepts which might come in handy down the road:
TABLE WITHOUT ID - This is just to remove the first column, so that we can add it later on with a different name
file.link as NPC – And here we add that column using as NPC to rename the column from “File”
FLATTEN .... as Location - This a way to avoid having those pesky operations in the column definitions, and it also allows us to use Location elsewhere in the query for either limiting or output, or sorting it and so on
SORT Location – Can be followed by asc or desc, to sort in either direction
Im so sorry but after some work and experimenting, and attempting to look at the documentation-
How do you implement a filter for a portion of nested tags?
Currently just displaying file.tags but dont know how to filter how by certain tags.
For instance, essentially having the field display what faction they belong to.
IE: #faction/KingdomofArdens or any subtag starting with #faction/*
TABLE WITHOUT ID file.link as " ", Location as "##### Current Location", file.tags as "##### Allegiance"
FROM #NPC FLATTEN regexreplace(file.folder, ".*\/([^\/]+)$", "$1") as Location
SORT Location
There’s no way to glob a filter for nested tags is there? I just wish to display a certain nested tag and this will help for other fields later on too.
As a bonus, how would I also just clip the end of the tag to ONLY display the last half of the nested tag…?
NEVERMIND! I found several methods and was learning a bit on the way. I may make a post about this so others who search for the same will be able to figure out more and at the very least do some reverse engineering of their own when they are new like me.
EDIT: I was typing when you posted the message above. Leaving this here just in case it helps anyone else.
This works in local tests:
```dataview
TABLE WITHOUT ID
file.link as " ",
Location as "##### Current Location",
filter(file.etags, (x) => contains(x,"#faction/KingdomofArden")) as "##### Allegiance"
FROM
#NPC
AND
#faction/KingdomofArden
FLATTEN
regexreplace(file.folder, ".*\/([^\/]+)$", "$1") as Location
SORT
Location
```
This works too! Thank you. I had developed a method where it actually may be useful to have multiple tags still showing as well but yours is great and more simpler than mine!
(The only thing wrong was the AND #faction/KingdomofArdens as that limited the queried files to only those with that tag but still better method than I had.
```dataview
TABLE WITHOUT ID file.link as " ", Location as "##### Current Location", filter(file.etags, (x) => contains(x,"#Faction")) as "##### Allegiance"
FROM #NPC
FLATTEN regexreplace(file.folder, ".*\/([^\/]+)$", "$1") as Location
SORT Location