Skip to content

Folder note template not applied when using Templater integration #322

@jottr

Description

@jottr

Bug description

When a folder note is created with a template path configured, the template is never applied to the new file. The file is created empty (0 bytes).

Root cause (from source analysis)

I traced the issue through the plugin source code:

  1. createFolderNote creates the file empty via vault.create(path, "") (in handleCreateFolderNote, the template logic at line ~3218 is gated by extension !== ".md", so it's skipped for markdown folder notes).

  2. applyTemplate is then called, which correctly finds the template file and detects Templater is enabled.

  3. applyTemplate calls templaterPlugin.write_template_to_file(templateFile, file) — this call completes without error but silently does nothing. The file remains empty.

Additionally, Templater's trigger_on_file_creation does not fire for files created by Folder Notes. When the Folder Notes template path is cleared and Templater's catch-all / folder template is configured, the folder note is still created empty. This suggests vault.create() as called by Folder Notes does not trigger the event that Templater listens for.

Two separate issues

  1. write_template_to_file silently fails: Templater's read_and_parse_template likely returns null in this calling context, causing the function to exit early without writing anything. No error is logged.
  2. trigger_on_file_creation not firing: Files created by Folder Notes do not trigger Templater's new-file event, so even with the template path cleared, Templater's folder template mappings are bypassed.

Steps to reproduce

  1. Install Folder Notes and Templater
  2. Create a template file (e.g., Templates/folder-note.template.md) with any content
  3. In Folder Notes settings → General → Template path, select the template
  4. In Templater settings, enable "Trigger Templater on new file creation"
  5. Right-click a folder → Create folder note
  6. The created note is empty — template not applied

Debug output

Added console.log statements to applyTemplate in main.js:

[folder-notes-debug] callsite: {folderNote: true, matchingExtension: true, extension: '.md', templatePath: 'Templates/folder-note.template.md', folderNoteType: '.md'}
[folder-notes-debug] applyTemplate called {filePath: 'Health/Supplements/Supplements.md', templatePath: 'Templates/folder-note.template.md'}
[folder-notes-debug] fileContent: "" length: 0
[folder-notes-debug] templateFile: Templates/folder-note.template.md found: true isTFile: true
[folder-notes-debug] plugins: {templaterEnabled: true, templatesEnabled: true, hasTemplaterPlugin: true}
[folder-notes-debug] templateContent length: 109
[folder-notes-debug] calling write_template_to_file
[folder-notes-debug] write_template_to_file returned: undefined

All checks pass, the template file is found and read, but write_template_to_file produces no output.

Environment

  • Folder Notes: v1.8.19
  • Templater: v2.16.4
  • Obsidian: desktop, macOS
  • File type: .md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions