Create a note and call a template in one step (no user function or 3rd party code editor)

Hi all
I just put together a 3-liner for creating a note and calling a template in one step rather than the 2-steps native to Obsidian. I thought i would share as it may be useful for some.
Most importantly, this does not require user functions (i.e. works on mobile as well) or any sort of 3rd party plugin/code editor to Templater.

In your template folder, create a note that will generate future notes for you (I called it ‘NewFile’).
Paste the below code:

<%*
const fileName = await tp.system.prompt("File name")
const templateName = await tp.system.suggester(["Template1", "Template2"], ["Template1", "Template2"])
tp.file.create_new(tp.file.find_tfile(templateName), fileName, tp.file.folder())
%>

Replace the sample table items “Template1” & “Template2” with the name of your templates in both tables on the second line of code above.

By calling this template with code (‘NewFile’), a free text box will appear to enter your note’s name (NOT title) and a drop-down will then appear to let you choose your template from the list you have entered (in the second row above). I personally use notes’ frontmatter with a field ‘ChildrenType’ to predefine which templates to pre-populate as i use that script for all my master notes…

For you to then create a note, either call the ‘NewFile’ file from the command palette (‘create a note from a template’) or create a button somewhere (with the Buttons plugin):

\```button
name Create Note
type append template
action NewFile
\```
8 Likes

This is super awesome and I have been using it. However, every time I create a new note it jumps me to a blank Untitled file and keeps it open. The new note I made with this method also gets created perfectly but I have to go and delete the Untitled note and then open the one I created with this method. Can you possibly help me? Thank you in advance!

Unfortunately this is deemed to happen if you launch this from the command palette.
To avoid this, create a button on a note that links to your macro or use templater user functions

Yes! Thank you! I will try that now. I’m just glad it’s expected behavior and you gave me a solution! It’s been driving me crazy! Thank you so much!

Ok I got it working! Thank you so much!

This solved an issue I was having thanks so much!

I now have a way of using a button to create a new note that I can name on creation. Tried the rename method but it was having issues with the dataview blocks in my template. Having the templater factory solved this.