Bases Basic: Displaying Notes in the Same Folder

Overview

Obsidian’s Bases (database) version 1.9.10 has been released, and I’m sure many people are wondering—what’s it good for?

This article introduces its usage with a simple example, while also serving as a step-by-step “follow-along” tutorial.

The Result

Let’s first look at what the database can achieve:

r/ObsidianMD - This vault is Kepano's example vault|750xauto

This vault is Kepano’s example vault

The purpose of this Base is quite simple: display other notes in the same folder as the current note. Perfect for when you’re browsing notes and want to quickly check out other related notes nearby.

Implementation

First, right-click in the file explorer and create a new Base file:

r/ObsidianMD - Create a new base|353xauto

Create a new base

After creating it, give it a name, for example base-SameFolder:

r/ObsidianMD - Your first base|750xauto

Your first base

Then you’ll see the basic state of Bases: A table containing all files in your vault.

Next, we need to understand the two most important fundamental concepts: filters and properties.

Concepts

The most important part of the database is in the top operation area, which includes:

Top left:

  1. Views
  2. Results (including CSV export, result count limits, etc.)

Top right:

  1. Sort
  2. Filter
  3. Properties
  4. New

We’ll focus on the most important Filter and Properties first.

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|623xauto

Filters

Filters define the “conditions for display”.

By default, all files will be listed, but too much information equals useless information. So we need to define what we want to see.

In this case, the condition is “in the same folder as the current note”.

Properties

Each file has its own specific properties. Properties can be used in “filter” conditions and also as “displayed information”. Besides the properties in the Properties area at the top of notes, there are also some implicit metadata, such as file paths, file folders, etc.

For this case, we need to get the folder property.

Practice

Specific Folder

Click the Filter button to open the filter UI.

We’ll open the “All views” filter and select: file | in folder, meaning “in a specific folder”.

r/ObsidianMD - Basic filter|620xauto

Basic filter

Then we can manually enter a folder (path has auto-completion) to see the effect:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|750xauto

You can see that after this configuration, we can already display notes from a specific folder.

Let’s celebrate this important first step with your Base! :partying_face:

Formula: Dynamic Filter Conditions

But our goal is to display notes in the same folder as the current note.

We can’t manually modify the folder path every time, right? So we need more dynamic filter conditions.

First, click the </> button on the right:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|620xauto

Enter the advanced filter editing interface:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|620xauto

You can see that the filter condition has now become a formula: file.inFolder("References")

Its meaning is exactly the same as the previous filter: file is located in folder Reference.

:light_bulb: The formula is somewhat like Javascript code, but relatively simple. You can learn by first building simple filters and then switching to advanced filters.

Here file refers to each file being tested—if it meets the condition, it gets listed in the results. So our next step is to replace the folder Reference with the actual current note's folder.

Specifically, replace "Reference" with this.file.folder:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|620xauto

You can try this modification first to see the result, then we’ll explain the theory.

About the Current File

If all goes well, after entering this, you’ll see files from the folder where the current base file is located:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|750xauto

(There might only be itself)

Now we need to introduce the special variable this— it represents the “current” file, but this “current” depends on where the Base is located.

For example, we’re currently editing the Base in the main editor, so this base-SameFolder.base is the current file.

But if we drag the base file to the sidebar and then click on the current note, things will change—

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|750xauto

When the Base is in the sidebar or a split editor, this represents the currently active file.

This is a very important feature, and it’s based on this feature that we can achieve the “other notes in the current note’s folder” functionality.

Oh, by the way, in case you haven’t noticed, when you get to this point, you’ve already achieved the effect we wanted from the beginning :wink:

Congratulations! :tada:

Principles and Tips

In principle, our final filter condition: file.inFolder(this.file.folder) means we first use this.file to get the “file object” of the currently active note, then get its folder information through .folder.

Here’s a little tip: you can click Properties → Add Formula to add formula properties:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|412xauto

After entering file., you’ll see its various properties:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|625xauto

When you enter the complete file.folder, you can see this property for each file:

r/ObsidianMD - Bases Basic: Displaying Notes in the Same Folder|625xauto

This is also a practical tip for testing bases formulas—try other properties too!

r/ObsidianMD - e.g. Full name of each file|625xauto

e.g. Full name of each file

Summary

This time we tried:

  1. Creating a new Base file
  2. Adding filter conditions to display the notes we want
  3. Moving the base to the sidebar to get dynamic filter results
  4. Understanding basic file properties

I hope this article serves as an easy start to your base journey. Have fun exploring!

Moi moi! ( ̄▽ ̄)ノ

Resources

Here are some related resources for extended learning.

Base Documentation

Bases syntax - Obsidian Help Basic syntax for bases. I recommend checking this documentation before (or after) practicing to get solid foundational knowledge.

In the Properties section, you can see introductions to note properties and file properties; On the Functions page, you can see introductions and applications of formulas/functions.

Example Vault

kepano/kepano-obsidian Kepano’s shared Obsidian example vault. He has converted all the filters in the vault to bases database format, where you can learn many usage patterns.

16 Likes

Such an elegant solution.

I have a folderless structure, but with Bases and frontmatter I can definitely see myself using a similar system to display suggestions for movies by the same director or with the same “genre”, the actors, etc

1 Like

Yes, just a simple tweak to the Filter will achieve the effect you want. You’ve got it! :partying_face:

Thanks, I just learned about Bases and I didn’t know you could display it on the sidebar!

I was wondering what was the difference between “file is in folder” (file.inFolder(...)) and “folder is” (file.folder == ...), and the latter means being exactly in that folder (direct child), as the code suggests, whereas the former is also true for files in any sub-folders.

Since the former will show a great number of files including images, I had to filter a bit further, so I added a “file extension is md” filter condition to exclude images and only show actual pages.

My use case: I have a huge list of game titles with screenshots, one page per game genre, one heading per sub-genre or country, one paragraph (sometimes sub-heading) per game title. This hierarchical system makes it complicated to cross-search (for instance, how to find all games made in Germany across all genres?)

It looks like a “flat hierarchy” with all game pages in the same folder and using tags for genre and country would allow me to make the filtered views I want (by genre, sub-genre, country). Unfortunately, that means I’d need to convert each game paragraph into its own page (which would be a very short page), and file navigation inside a huge folder wouldn’t be convenient at all. I suppose that the Card view (with game screenshot as thumbnail, like a Steam game library) + filters would save the day, but I still need to choose to take the plunge (and on the technical side, I need a script to convert all my game paragraphs / headings into pages).

Either way, for now I’m just putting some generic Bases view on the sidebar that displays page tags and I’ll see if it’s worth converting my entries into small pages.

After the last update, both file.inFolder(this.file.folder) and file.folder == this.file.folder stopped working.

1 Like

Thx for the tip. Its working fine for me.
(on last insider build)

Please, @hasanyilmaz , which tip?

Last Modified Files in sidebar (Edit: I use like that). Good explained tip. Whole topic I wanna mean. Its working.

file.inFolder(this.file.folder)

I can see other files in the same folder now with that.

Oh, this part! Thank you! I was expecting to not have to do that.

Thank you so much!

1 Like

All my notes have a category key, such as

category: [[Books]]

All of my notes have tags, such as:

tags:
  - Books
  - Authors
  - Publishers

As well as:

file.inFolder(this.file.folder)

I also have other views in the same base to track category and tags:

category.contains(this.category)

file.tags.containsAny(this.tags)

By using this.category and this.tags, it is easy to find other notes that have the same category or tags as the current file.

Expect I will add more views in time.