Bases: Nested tags support

Use case or problem

The new bases filter tags.contains("...") doesn’t support nested tags (can’t insert links but its in the docs). For example, if you use tags.contains("recipe") as a filter then files with the tag #recipe/snack or #recipe/cookies won’t show up.

Proposed solution

The filter tags.contains("...") behaves like an array search. Adding support for nested tags can be done by “expanding out” a file’s list of tags. Using the example above, a file with #recipe/snack tag would be treated by the bases plugin as an array with both #recipe and #recipe/snack tags.

Current workaround

While the bases syntax is very powerful and allows for many smartly crafted workarounds, many have their own set of downsides or issues. In my opinion having to figure out any of these workarounds kinda defeats the point of nested tags. Its in the Obsidian docs so it is an official feature all things considered. It only makes sense that all core functionality treat nested tags how the user would expect.

7 Likes

Does file.hasTag("recipe") do what you want? It’s searching the tags: Property as well as inline #tags.

The downside to that workaround is it also includes files that contain that tag inside the body of the file. tags.contains("...") only accounts for frontmatter/properties, which is much more desirable for most.

Desperately needing this as well!

I can image some potential circumstances in which I wouldn’t want my Bases to reveal all nested tags, but it could still be a pain to exclude each one of them individually - perhaps some syntax like tags.contains(recipe/**) to indicate the tag and all nested tags vs without the asterisks just returning the tag itself, as is current behavior. Although I’d love for nested tags to be included as the default, I’m not sure what the syntax would be to exclude all nested tags if that is the case.

1 Like

Unique syntax is a good potential solution. Maybe a unique function for when you do (or don’t) want to use nested tags? Like tags.containsNested("...") or tags.containsExact("...")?

As a workaround in the meantime, you can do:

or:
  - tags.contains("recipe")
  - tags.toString().startsWith("recipe/")
  - tags.toString().contains(", recipe/")

That gets you the Front Matter tag and its nests without pulling in inline tags.

It rules out all of the false positives that I could think of, making sure that a tag like #great-recipe/squash doesn’t accidentally get included.