Skip to content

Folder templates with Templater code cause empty file to be created #1663

@jboehm77

Description

@jboehm77

Plugin information (please complete the following information):

  • OS: Windows 11
  • Templater version: 2.16.2
  • Obsidian version: 1.10.3
  • Templater settings: Template folder location - Resources/Templates/

Describe the bug

When creating a file in a folder with an assigned folder template that contains Templater code, an empty file is generated. The same template when called from a Meta Bind button works as expected. Templates without Templater code also work via folder templates as expected.

Expected behavior

Templates should function comparably whether called directly or via folder template.

Screenshots

Prompt when making new file in folder with a folder template:

Image

Result:

Image

Additional context

#1652 seems to mention a similar issue, but claims the problem was resolved in an update. This does not appear to be the case on the most up-to-date versions of Obsidian and Templater as of the writing of this issue.

Example Templater code being used in templates (placed immediately following frontmatter and before the rest of the file contents):

<%*
const hasTitle = !tp.file.title.startsWith("Untitled");
const hasMoved = tp.file.folder().startsWith("Notes");
let title;
if (!hasTitle) {
    title = await tp.system.prompt("Enter Note Name");
} else {
    title = tp.file.title;
}
if (!hasMoved) {
    await tp.file.move("/Notes/" + title);
} else {
    await tp.file.rename(title);
}
_%>
# <%* tR += title %>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds reproReported issue needs to be reproduced

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions