Create a new note from template passing parameters

Hi,

I have a PKM where some notes represents COMPANIES and others PEOPLE working for this companies.

I would like to have a button called “Create People” in the COMPANY note that automatically creates a new PEOPLE note (based on PEOPLE_TEMPLATE) with a backlink to the COMPANY note.

I’m using “templater” and “obsidian button maker plugin” but I’m not able to pass the name of the company to the new note.

The only solution I found is create a note with the name of the company and then, via javascript, grab it and put in the note and rename the new note with the name of the person… but it’s complex, fragile and prone to errors…

Any idea?

Thanks,
Gianluca

1 Like

I have the excact same issue. Did you come up by a solution?

1 Like

Have you seen the tp.config.active thingy?

https://silentvoid13.github.io/Templater/internal-functions/internal-modules/config-module.html#tpconfigactive_file

Not sure if this triggered when hitting a button, but it seems like it would be natural, so then you get that file (and have access to all fields/information from it).

I tried this but got stucked. https://forum.obsidian.md/t/templater-for-parent-child-structures-meeting-minutes-workflow.

I not sure how to extract e.g. note titel from the tp.config.active_file object.
From the example below I would like to create NoteB from a template called when NoteA is active?

NoteA

title::blablabla

NoteB

refnr: [[Note A]]
title::blablabla

new note template

<%*
 let  active_file = tp.config.active_file;
-%>

title:: <%active_file.tags.title%>
summary:: 
refnr::[[<%active_file.title%>]]
1 Like

fwiw, i’d love to understand how to do this as well…would vastly improve my work flow

I use qucikadd which works with templater. look at the quickadd docs about using both. i assign a hotkey to the action to create the note. quick add can prompt for input.

This brings me close but I dont understand the lastFile. Its not the file I open and activate the templater from.

templater file:

<%* 
let new_titel = tp.date.now("YYYY-MM-DD_HHmm")
tp.file.rename(new_titel)
await tp.file.move("daily notes/" + tp.date.now("YYYY") +  "/" + tp.date.now("MM") + "/" + new_titel)
let files = this.app.workspace.getLastOpenFiles();
let lastFile = this.app.vault.getAbstractFileByPath(files[0]);
%>
summary:: 
refnr:: [[<%lastFile.basename%>]]

QuickAdd is very powerful but I’m not sure how to achieve what I want. I want to create a new note with no prompt for note title etc.

I’ve dabbled a little with various ways to create new notes, and that triggers the various options discussed here differently. So for us to help you the best, could you please describe exactly how you would like it to be?

Do you start with hitting a link to a file not created yet? Do you hit a hotkey to create the new file? Do you have setup stuff which triggers templates on creation of new files? Do you hit a hotkey to insert the template? Could you provide the code for your button? Are the company note in the same folders, as the people notes? How does your way of creating files differ, @gianx and @atomman?

If you give a precise description of the steps you want to take, and the result you would like out of it (even though it’s not happening like that today), it would be easier for me (and others) to recreate that, and do proper tests to achieve your end goal.

I have solved my issue and possibly also @gianx issue.
Im using the buttons plugin to create a new note from a template with backlink to parrent file by the push of a button.
The buttons code for a specific case note has the following syntax in my case template file.

name case_note
type note(tmp-<%tp.file.title%>) template
action case note 1
templater true

This ensures that the button creates a note called tmp-<CASEID> from a template called case note 1 which will pull the CASEID from the title and insert it as a backlink. In addition Im passing metadata (a field called titel) from the parent not to the child via DataviewAPI.page object.

case note 1 templater file:

<%*
   const dv = this.app.plugins.plugins["dataview"].api;
	let refnr = tp.file.title.slice(4,10);
   
   const fooMeta = DataviewAPI.page(tp.file.find_tfile(refnr).path)
   let new_titel = tp.date.now("YYYY-MM-DD_HHmm")
    tp.file.rename(new_titel)
   await tp.file.move("daily notes/" + tp.date.now("YYYY") +  "/" + tp.date.now("MM") + "/" + new_titel)
-%>
---
type: case_note
titel: <% fooMeta.titel %>
---
summary:: 
refnr:: [[<%refnr%>]]