In Dataview table, I only want to display the last subtag (for example ‘Graphic’). However, when using file.etags, the full tag (e.g. ‘Software/Graphic’) is shown instead. How can I extract and display only the last subtag?
There has been some addition to dataview making this a little nicer: map(file.etags, (t) => slice(split(t, "/"), -1) This would pick the last part of any nested tag within file.etags.
Thank you for your amazing solution! I do have a small issue, though. When a tag is not nested and consists of only one word, Dataview displays it with a # at the beginning. Is there a way to remove the # while keeping the code clean? Thanks again!
So you don’t want the hash tag… Then you could do replace(t, "#", "") or substring(t, 1) instead of the t inside of split. Or you could do a regexreplace on the entire string, maybe something like regexreplace(t, "#.*\/?(.*)", "$1") instead of the slice and split combo.
All of these are untested, and written in the dark of the night, so if they’re not working I’ll do better tomorrow.
Here is a complete working example with all three variants on removing the # and splitting the remaining and only listing the last part of a nested tag.
```dataview
TABLE
join(map(file.etags, (t) => regexreplace(t, "#(?:.*\/)?(.*)", "$1"))) as regexreplace,
join(map(file.etags, (t) => slice(split(replace(t, "#", ""), "/"), -1))) as sliceSplitReplace,
join(map(file.etags, (t) => slice(split(substring(t, 1), "/"), -1))) as sliceSplitSubstring
WHERE file = this.file
```
Based on the example file provided by @Guapa , this gives: