Folder & Template suggester during note creation

(See section “References” for templates & demo vault).

When I came across a feature request on these forums a few weeks back, for a challenge I have resolved for myself in the past, I felt the time for me has come to contribute something back to this fantastic community.

So I am sharing installation instructions and a vault demonstrating one of my workflows with you.

When the creation of a new note is triggered in my vault, this workflow presents me with dialogs to chose a template to apply, as well as for the selection of a folder location for the note. It works for both notes created through a dead Obsidian link, as well as those triggered through the “Create new note” command.

The workflow is one of the key enablers to my PPKM (Personal Productivity and Knowledge Management) practice.

Whilst I decided to undertake the effort to create this post in response to Choose a folder whenever a new note is created from a link, I now believe the “Share & Showcase” section is a more suitable home for it. I hope this is ok.

Disclaimer

This solution utilises Javascript, yet I am not a Javascript developer.
My code does what I want it to do, but you should be aware that the template I am sharing with you is far from perfect. Any improvements are welcome.

Use at your own risk!

Installation

These are quick-start instructions to get you up and running with my note creation workflow and a first basic ‘New Note’ template in the vault of your choice. To avail of all workflow capabilities you will need to create additional templates and modify the script to meet your needs - or take a copy of my demo vault. You’ll find the downloads in section “References” at the end of this post.
Quick-start instructions:

  1. Make a backup of your vault - or create a new one for try-out.

  2. Did you create a backup of your vault? :wink:

  3. Install & enable the Templater plugin (available in Obsidian’s ‘Community plugins’ section)

  4. Drop the New Note.md & Note Creation Dialog.md templates provided into your designated template folder. In my vault the location is zzSystem/Templates/Templater, yet the location is up to you for as long as you amend paths in the next steps accordingly.

  5. Should you not have a default folder to create new notes in - create one. I call mine _seedbox (as assumed throughout this post). yet any valid folder name of choice will do.

  6. In Obsidian settings: Configure a “home” for new notes: In settings > Files and links > Default location and select In the folder specified below. Add the name of your folder for the option Folder to create new notes in !

  7. In the Templater settings, set the Template folder location to the folder from step 4.

  8. Still in the Templater settings, configure default template execution against the „home“ folder you have configured in points 5./6 for new notes:

    • activate the option Trigger Templater on new file creation. This will enable a new section in settings called Folder Templates
    • In section Folder Templates, ensure the option Enable Folder Templates is active
    • Still in section Folder Templates, fill in the Folder (your “home” for new notes) and Template (the Note Creation Dialog template). Your Templater configuration should now look similar to this screenshot
  9. If you followed the instructions (and I provided them correctly - I did test them, I swear;-), you should now see the workflow kicking in when you create a new note from a link, or via the Create New Note (CTRL-N) command. If not, your next test should be to disable all plugins but Templater and restart Obsidian. Be aware, that all template options apart from the ‘note’ template are defunct until you a) create additional templates and b) either adapt the script to your needs or extend your vault structure to be compliant with the folder structure expected by the script:

Vault structure

As mentioned in an earlier post, I consider my setup highly opinionated. My vault structure is one of the enablers to my practice. It incorporates a mix of some aspects from PIM, CRM, GTD, Zettelkasten and provides the static, vertical capabilities of PPKM:

What the script does

My solution is enabled by SilentVoid13’s Templater plugin for Obsidian and is implemented via a central Templater template I call Note Creation Dialog.
The central template contains Javascript utilising the tp object provided by Templater to

  • generate modals, asking the user to select a template, folder and optionally a name for the note in case note creation was not triggered via a click on a link
  • move (and rename if needed) the newly created note to the folder selected by the user
  • enrich the template selected by the user with links to “parent information” where applicable
  • apply the selected template
Common functionality
  • Provide the user with a modal dialog to select a template to be applied to the new note
  • Provide the user with a modal dialog to select the folder to create the new note in. Limits options offered based on the template selected, where applicable (see below)
  • If the new note was created from a link, use the name of the link as the note name, otherwise ask the user to provide a name for the note
  • Add links to the Venture/Workstream or Product/Component at the top of the note where applicable (based on the folder path selected by the user) whilst updating the new note with the user-selected template
Functionality depending on selected template
Template Folder Path Comments
Meeting ask user 1. Prefixes the name of the note with the current date
2. Adds links to the “Venture/Workstream” or “Product/Component” from its folder path at the top of the note where applicable.
Note ask user 1. Adds links to the “Venture/Workstream” or “Product/Component” from its folder path to the top of the note where applicable
Contact /Actors/ *
Organisation /Actors/ *
Circle /Actors/ *
Product /Catalogue/
Component ask user 1. User choice for folder selection is limited to folder paths containing Catalogue/
2. Creates a new subfolder and folder note underneath the user-selected “Product”
3. Adds a link to the “Product” at the top of the note
Venture ask user 1. User choice for folder selection is limited to folder paths ending in /Ventures/
2. Creates a new folder and folder note from the user-provided name
Workstream ask user 1. User choice for folder selection is limited to folder paths containing Ventures/
2. Creates a new subfolder and folder note underneath the user-selected “Venture” from the user-provided name
3. Adds a link to the “Venture” at the top of the note
*Contacts may be assigned to Circles and/or Organisations via note properties (not part of this workflow)

Sample note “End user test session 1”, created against a Workstream called “Quality Assurance” from a Venture called “PPKM Solution”:

Credits

First, big shout-out to SilentVoid13 for his awesome work on the Obsidian Templater plugin. Like all open source work here, turning abstract ideas into reality, plus taking on the risk from exposing oneself’s ideas to the public, is super impressive. Hats off to that bravery and a huge thanks to all contributors in this community for their “sharing and caring”.

Second, to the creators of Obsidian. With their product and approach to the market, they created a dark horse that makes the world a little bit better for us and created the fertile grounds to enable this community.

Thank you.

Q & A

  • Q: Nice try, but a plugin to address the same issue already exists.
    A: Should that be the case, please do let me know the name of the plugin - I am always happy to learn.

  • Q: Since using your workflow I have a folder called “null” at the root of my vault
    A: Mea Culpa - it’s a bug. Please report. Until two weeks ago, when I took the decision to publish my workflow, I simply hadn’t catered for the situation where a user wants to cancel out of the workflow. It was just faster for me to delete unwanted artefacts - but I don’t consider same good enough for publishing. So I updated my code after a year of use to cater for user cancellation, yet the related changes have merely seen manual testing and a week of use in production so far.

  • Q: Since using your workflow I have “Untitled” notes in my seedbox/inbox
    A: Same as the previous answer.

  • Q: The note name has underscores - this is not what I entered
    A: The file name of a note is the note name + the .md extension, so there is a dependency between note name and file name. Your Operating System does not allow the use of certain characters in file names. Invalid characters include * " \ / < > : | ?. When any of those characters are part of the note’s name to be created, my workflow would just bail and leave “null” folders and/or “Untitled” files behind (see previous questions) - good enough for me, but not good enough for a release. So I decided to replace any such characters in the note name provided with underscores, to neither break the workflow nor the “users flow”. I thought about presenting the user with another modal dialog to ask what they want to do, or gracefully cancel - yet, the purpose of my workflow is to reduce cognitive load, so in the end I decided to go down the character replacement route instead.

  • Q: Why do you add links at the top of the note when the note is already in the correct folder?
    A: There are several reasons, yet the most important one is to ensure compatibility with Obsidian’s concept of links: A link connects your notes, a folder structure does not. For illustration look at Obsidian’s Graph View and you’ll see what I mean. These concepts align beautifully with PPKM, where Folders satisfy the „necessary evil of logistics“ to enable verticals. In PPKM folders have no „intellectual value“, yet they free up tags and links to be used for the latter.

  • Q: Why do you prefix the name of a meeting note with a date?
    A: Think ceremonies (weekly-, daily meetings etc.) - you often have a single name for the series, yet you likely want all meetings of that series in the same folder. This will run you into a conflict: A note name must be unique within a folder. By default my workflow makes five attempts to append a note name with a number if the desired name already exists in the target folder, yet this is intended as a fallback only. IMHO, prefixing a meeting note name with a date-stamp is more elegant and intuitive than a number suffix, and comes with some additional benefits (e.g. when you want to sort them, or need to find one against the „time latch”). You will find that Obsidian gracefully takes care about updating the links to a note when the note name changes, which makes this approach possible.

  • Q: It does not work
    A: After following the installation section, only the prerequisites for the flow “note” are in place (and should work). I only provide you the template for a “note”, since it is the least opinionated and works with any folder structure. You will still be missing the templates (and possibly folder structure) for the other flows. You will need to create them yourself and also amend the script in the central template, should you chose a different folder structure (or use my demo vault to aid adoption).

  • Q: This all sounds to alien to me. I just want your workflow to work in my vault.
    A: If you believe the settings dialog of a plugin would help you bridge the gap, vote for the functionality to become a plugin. If you are not alone, we can create one together (between design, documentation, QA, logistics and maintenance there is more involved than just writing a script - and I am an amateur in half of these disciplines;-). If you end up being the only one, it will be more efficient for us to amend the script together.

  • Q: I want feature X implemented in your workflow
    A: Depending on the number of requests, this might be another reason to consider “plugin-ification”, simply because of logistics. So, let me know what you are looking for, but please understand that me suggesting same is not an indication of any ability to comply with your request. I will need to gauge what comes in, what is feasible. The only commitment I can give at this point in time is to stand up a project and repository, should community interest warrant the effort.

  • Q: I want to know more about that practice you call PPKM
    A: Same as for a plugin: Should there be a wider interest in the community to read about PPKM, I will try to start documenting what I call “a knowledge management practice for the rest of us” - as time permits.

References

  1. Templates “New Note” & “Note Creation Dialog” NewNoteTemplate_NoteCreationDialog.zip (5.2 KB)
  2. Demo Vault Demo Vault Workflow Syrupnas.zip (890.0 KB)
7 Likes

This is brilliant! Very useful, this is exactly what I was trying to implement. Thank you a lot for sharing.

(deleted my previous post since the option to edit same had expired)

Thanks for letting me know @awerebea - delighted to find that my efforts are of some use.

Patch 1 :wink:

Using the flow daily, I discovered that the regex expression I used to replace invalid characters in note names with underscores required further refinement, since it had the side effect of converting some valid characters to underscores as well.

Meanwhile I have updated the line containing the regex expression from

fName = fName.replace(/[^\w\s]/gi, '_');

to

fName = fName.replace(/[^()-.\w\s]/gi, '_');

to ensure it does not convert any of the characters ()-. as those are valid in file names.

Let me know should you require any assistance with the change.

This is excellent and I am learning by examining the demo vault. As I am trying to incorporate parts of this I have a question: How can I change the “Ventures” folder to say be called “Aspects” and the Life folder to “Core” for example. similarly for “Actors” without breaking things (and rename the templates for new ones of these of course).

Thank you

So I learned some more scripting language and can now see how to get different folder locations etc. Thank you for a wonderful start. Now I need to work out how to get things automagically into the properties variables

Hi @danraymond,

Yeah, with the exception of renaming the Life folder you will need to dive into Note Creation Dialog .md for what you are trying to achieve. Here are some pointers from the top of my head to get you started (I suggest you have the script open in your preferred editor using its search capabilities to identify relevant sections as you read this).

Flow control

Key is the array myTemplates. Its definition is similar to

const myTemplates = ["Note", "Meeting", "Contact", "Organisation","Circle","Venture","Workstream","Product","Component","Case"];

Execution control of the script starts after the line

// ------------ Entry point ... -

The code before the entry point contains mainly function definitions. Most of these functions are called in the switch statement further below the entry point. The case branches of the switch statement test against the template selected by the user, which was stored in fTemplate, as returned by the function selectTemplate().

If you want to change the name of an option exposed to the user and/or the steps executed - this is the basic flow-control to consider.

Changing script behavior for a given template

Within the case branches you’ll find the sequence of steps executed against a template selected. You can modify/extend those steps according to your needs.

Integrating a different template

In the case branches you will also find calls like

output = await tp.file.include("[[New Note]]");

This example reads the template New Note.md and adds its contents to the variable output.
The latter contains the contents of what is written to your new file at the bottom of the script via the Templater variable tR:

tR +=`${output}`

Adding (dynamic) content to a template

This script is executed as a Templater script. This means that all variables defined within the script are available to the Templater plugin during script execution - and you can access them in your template definitions. For an example take a look at setClassification(). The first line of this function sets a couple of variables to an empty string…

root_category = root_link = root_label = parent_category = parent_link = parent_label = "";

… and later populates them, depending on the context in which the function was called.
When you look at the template New Note.md you’ll find that those variables are referenced in the template…

MOC:
Status: #fleeting 
<% root_label %> <% root_link %>
<% parent_label %> <% parent_link %>

… which results in note content like e.g. …

Venture:: [[My Project]]
Workstream:: [[My Workstream]]

for a note created in the folder Work/Ventures/My Project/My Workstream.

There might be a better approach these days to populate properties in the YAML-frontmatter, yet I don’t see a reason why this shouldn’t work just as well for the frontmatter, in analogy to the way I set the created: property in the same template.

Good look - and keep in mind that you may need to amend plugin configurations as well, depending on the naming conventions you want to introduce.