Templater User Scripts Obsidian
makeNoteWithPromptingThis script, inserts or creates a new note from a given template in a specified
location and prompts the user for the relevant note creation and
template variable. It also handles incorrect template configuration,
cancellation events, and other errors. The script is intended to be used as a
user script for the Templater plugin.
The following provides an overview of the topics covered on this page:
tp.user.makeNoteWithPrompting(tp, config, ext)
The following arguments, in the presented order, are required:
tpThe Templater object passed from the context of a template.
configThe configuration object that holds relevant note creation and template
variables. Each template variable holds a single configuration object, that is
composed of an arbitrary number of configuration elements objects. See the
documentation for the prompt user script for how the
configuration object should be structured.
If Templater is invoked via the command Templater: Create new note from
template, the configuration object must contain at least two elements named
exactly path and filename as indicated below.
// The configuration object.
let config = {
// The `path` element indicating where to create the note.
path: {
prompt: true,
display: "Please indicate the path.",
value: "Folder"
},
// The `filename` element indicating how to name the note.
filename: {
prompt: true,
display: "Please indicate the file name.",
value: "A new note"
}
}
There are no restrictions for the number and name of configuration elements when
the invocation occurs via Templater: Open insert Template modal.
extThe extension of the resulting note file. This argument is optional and set to
.md by default.
The makeNoteWithPrompting function call returns a promise that fulfills to the
TFile representation of the newly created note when Templater is invoked
via the command Templater: Create new note from template, or undefined when
Templater is invoked via the command Templater: Open insert Template modal.
In case of checking and processing errors, or user cancelling the prompting
process, the promise will fulfill to undefined.
Please check the documentation for the prompt user script for
detailed examples on how to use the makeNoteWithPrompting script.
The following video show the makeNoteWithPrompting script in action: