Prepend current note Title to newly created child note?

  • Is there a way to use Templater or some other obsidian plugin, to “prepend” the current note name to the newly created note? So if I’m in a note named “Test_Note_Parent” and I select some text in that note… Say I select the word “Child” and type in the doubles [[]] brackets to create a new note. When I click to add the note, it will create the note with the name as “Test_Note_Parent:Child”

Basically creating a new note with the selected text as the Note name, but Prepending or prefixing the current note name to the beginning of the newly created note?

Just thinking through the question…

Getting Templater to add a template to a New Note on creation is fairly easy, the hard part of this is that you only want it to do this when you are creating the New Note from clicking on the yet-to-be-link [[…]] within an existing note. As opposed to clicking on the New Note button at the top of the navigation.

I think that you would have to have Templater listening for an Obsidian API call for that particular within-note link note creation.

I’ve seen enough examples here to know there is a way to add titles dynamically for your parent-child name idea, but the real problem is how to recognize the link-to-note creation event as opposed to a New Note creation event. I’m not sure there really is a difference.

If you want, you can do it by triggering a templater script via hotkey. I recently created a script that does something very similar, here it is modified for your use case:

Script to create note from selection and prepend parent name
const editor = app.workspace.activeLeaf.view.editor;
let selection = editor.getSelection();
selection = selection.replace(/[#/|^]/g, ""); // remove disallowed characters

const parent = app.workspace.getActiveFile();
const pName = parent.basename;
let childName = selection.split("\n")[0].replace(/[#/|^]/g, "");
	childName = pName + " > " + childName + ".md";
let childContent = "parent: [["+pName+"]]\n***\n";
let child = app.vault.getAbstractFileByPath(childName);
if (child) {
	console.warn("child note with this name already exists.  Using existing file.");
	app.vault.modify(child, childContent + await
else child = await app.vault.create(childName, childContent);


// Lastly, open the child note in a new pane
const leaf = app.workspace.splitActiveLeaf()

Then you can trigger it with a hotkey via Hotkeys for templates plugin.

There might be a way to trigger it on note creation like you said, and if there is, I would love to know how to do that as well!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.