I am using the Templater plugin for Obsidian. I am clicking a link to a Note that does…
- User
I am using the Templater plugin for Obsidian. I am clicking a link to a Note that does not exist yet in Obsidian. I have Obsidian configured to always create new notes in a specific folder. Is there a way for Templater to know from which note the link was clicked which created the new note?
Assistant
Unfortunately, Templater doesn't have direct access to the information about which note the link was clicked from. However, there's a workaround you can try.
You can use the
tp.file.cursor()function in Templater to get the current file path. But in this case, it will return the path of the new note being created.To get the path of the note where the link was clicked, you can use the following approach:
- In your Templater template, use the
tp.file.selection()function to get the current selection (which should be the link that was clicked). - Use a regex to extract the file name of the note that the link points to (this will be the new note being created).
- Use the
tp.app.vault.getAbstractFileByPath()function to get the parent folder of the new note.
- In your Templater template, use the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.