Dec 2
Folder Notes
Source: [Discord](https://discord.com/channels/763107030223290449/104167157036…)
**TL;DR:** A folder note is a template that renders a note to display the folder contents and is read-only. The template can be modified to display things in a diferent way.
We want to customise the view of a folder:
- **configurable:** using nothing more than NotePlan
- **useful:** shows what we want it to show
- **dynamic:** updates when things change
There are several parts to the Folder display:
- The folder contents
- An optional `_index.md` note in the folder root
- An optional folder template note in the `Templates` Smart Folder
- A set of template functions for working with folder contents (TBD)
When I navigate to a folder, NP looks to see if there is a custom folder template. If so, it renders that. If not it renders a default template that looks like this:
```
—
name: Folder Template
type: folder-note
—
<%= folder.showIndex() %>
<%= folder.listNotesRecursive() %>
```
The `showIndex()` function renders a file called `_index.md` if it exists, otherwise it does nothing. The `listNotesRecursive()` function recursively lists the notes below the folder like it does at the moment.
Some other functions in the `folder.` namespace could be:
- `applyFilter(name)`: applies the named filter to notes below the folder and renders the results
- `showOpenTasks()`: shows open tasks in notes recursively
- etc.
If I define a folder template note in Preferences, then this is used as the template rather than the default.
My template might be:
```
—
name: My Folder Template
type: folder-note
—
## About this folder
<%= folder.showIndex() %>
## Contents
<%= folder.listNotesRecursive() %>
## Open loops
<%= folder.showOpenTasks() %>
```
This would be rendered dynamically whenever I select the folder. For deep note hierarchies this could get expensive, but for the 99% case it would be pretty quick.
Most of the contents could be cached, but that would be on a per-function basis I expect. I don't know how or whether the templating infrastructure supports this, but you could e.g. timestamp the various dynamic fragments and then check these against their sources. I don't know if the existing filter system already has something like this.
If I were implementing this incrementally, I would probably do this:
1. Render `_index.md` file if it exists instead of/as well as listing notes, in other words add index support as its own feature.
2. Introduce support for custom Folder Template.
3. Introduce more folder-level functions.
4. Allow different Folder Templates based on the folder path or from a `type` setting in the `_index.md` file’s metadata.
This would start to converge on the way Hugo renders categories. So project folders under a `Projects` root would render one way—showing open tasks say—and general notes under a `Resources` root folder might list notes by tag (which I just totally made up!).
Pending