Get parent note title for backlink on new file creation from empty link #799
-
How to get parent note title for backlink on new file creation from empty linkI know how to add the current note title (i.e. the newly formed note) by using this in the template: '# <% tp.file.title%> but how do I get the title of the note I linked from? I.e. the parent note title in order to create a hard back link? E.g. "Note A": "new file": I'm (relatively) new to Obsidian (and GitHub - sorry about originally submitting in wrong spot), and I imagine I may have to do some sort of JavaScript in my new file template to get the name of the most recently modified file (which I think would be the parent file), but is there an easier built-in way to get the parent note name for when you click or tap on a link to a file that doesn't exist yet? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Not an easy problem to solve. Can you provide some more context around when you would run the script? Are you creating the new file with |
Beta Was this translation helpful? Give feedback.
-
One easy implementation what you want is this: <%*
let files = this.app.workspace.getLastOpenFiles();
let lastFile = this.app.vault.getAbstractFileByPath(files[0]); // t file
tR+= `you last file is: [[` + lastFile.basename +`]]`
%> Add it to Folder Templates to trigger it when you create a new note or you can just use it as is. |
Beta Was this translation helpful? Give feedback.
-
My use case is to automatically insert the parent URL as a property into all newly created notes. For me, the parent URL is the note I am in when I create the new note. Trying the original solution was getting funky results because it uses the last open variable as opposed to the last active file (which could be different). It appears the following command produces the desired output. I have not rigorously tested this solution, and I am new to Obsidian and scripting so user beware.
|
Beta Was this translation helpful? Give feedback.
One easy implementation what you want is this:
Add it to Folder Templates to trigger it when you create a new note or you can just use it as is.
Demo