marcusolsson / obsidian-projects

Plain text project planning in Obsidian

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

{{title}} place holder in the template is not getting replaced by title

sunravi opened this issue · comments

What happened?

I used a YAML front matter File: [[{{title}}.pdf]]. If I use obsidian core plugin template, this gets correctly replaced with the note title. But the add notes in projects plugin, it is not replaced with title. Instead it gets .pdf without title.

What did you expect to happen?

I expect the same behavior as template core plugin.

How can we reproduce it (as minimally and precisely as possible)?

  1. Create a template and add the following YAML front matter
    PdfFIle: [[{{title}}.pdf]]

  2. Add this template to the project.

  3. Add note in the project using this template

Anything else we need to know?

No

Plugin version

1.8

Obsidian version

1.1.9

OS

Windows

image

image

image

I can see the problem. The create note modal doesn't define the title function:

date: (format) => moment().format(format || "YYYY-MM-DD"),
time: (format) => moment().format(format || "HH:mm"),

Here's how it should look like:

title: () => (record.values["name"] as string | undefined) ?? "",
date: (format) => moment().format(format || "YYYY-MM-DD"),
time: (format) => moment().format(format || "HH:mm"),

We should probably extract this into a shared function so that they stay in sync.

date: (format) => moment().format(format || "YYYY-MM-DD"),
time: (format) => moment().format(format || "HH:mm"),

{{date}} & {{time}} placeholders are used here for filenames, not for note contents, corresponding to the project config "Default name for new notes".
image

The actual problem is, the name that used to fill the {{title}} placeholder wasn't included in the data recored, so it's impossible to access the name using record.values["name"]. The limitation of creating file is, we should prepare the contents and parse the placeholder before the file is add by the filesystem, causing the filename also unavailable.

To solve it, I extracted the filename from the record id, then filled it into the {{title}}.

return {
id: path + "/" + name + ".md",
values: values ?? {},
};

title: () => (record.values["name"] as string | undefined) ?? "",
date: (format) => moment().format(format || "YYYY-MM-DD"),
time: (format) => moment().format(format || "HH:mm"),