Templater - chrisgurney/obsidian-note-toolbar GitHub Wiki

Install and enable the Templater plugin ↗ and use Note Toolbar to insert templates, create new notes from specific templates, and to execute Templater commands and files.

Note Toolbar's Scripting option must be enabled in order to use this feature.

Tip

See the examples folder in this repo for user scripts ↗ and templates ↗ that work with Note Toolbar. See also Zach Young's Templater Snippets ↗.

Use Templater commands in toolbar item fields

Use Templater commands in labels, tooltips, and URIs, to create dynamic toolbars.

For example, set your label to <%tp.date.now("MMM Do")%> to show today's date. Alternately use this syntax: {{tp: tp.date.now("MMM Do")}}

Note that the entire label/tooltip/URI must start with a <% and end with a %>. If you wish to include a fixed string as part of the output, the expression must output that string.

  • For example, this will not work: Daily Notes/<% moment(tp.file.title, ... %>
  • Instead, the command will need to append the string: <% "Daily Notes/" + moment(tp.file.title, ... %>

Functions available

After creating a new Templater toolbar item, select from one of the below functions.

Note

When selecting templates, files listed are based on Templater's Template folder location setting.

Insert template

  • Inserts the provided template in the current file, at the current cursor position.
  • Uses the append_template_to_active_file API method.

Create new note from template

  • Creates a new note from the provided template.
  • Optionally specify an output folder and filename (without the .md extension). Use a Templater command in this field to create a dynamic filename.
  • Optionally select a command to run after execution, for example: Files: Reveal current file in navigation.
  • Uses the create_new_note_from_template API method.

Execute Templater command

  • Executes the provided Templater command and returns the result.
  • The tags <% and %> are optional.
  • Execute user scripts with tp.user...
  • Uses the parse_template API function.

Example command:

tp.file.creation_date()

Execute Templater file

  • Executes the provided file and returns the result.
  • Make sure you include tp in the function's signature in order to use Templater's API within your scripts.
  • Uses the read_and_parse_template API method.

Example file:

/**
 * Adds a date stamp to the filename of the current file.
 */
module.exports = async function FileRename(tp) {
    tp.file.rename(tp.file.title + ' ' + tp.date.now());
}

Note Toolbar Callout support

For Note Toolbar Callouts, use these data attributes:

Function data-templater-obsidian data-src data-expr data-dest
Insert template appendTemplate template filename n/a n/a
Create new note from template createFrom template filename n/a output filename
Execute Templater command parseTemplate n/a templater command n/a
Execute Templater file parseTemplateFile template filename n/a n/a

Example:

> [!note-toolbar] Templater Toolbar
> - [Create from Template]()<data data-templater-obsidian="createFrom" data-src="Templater/Basic Template.md" data-dest="&lt;%&quot;Basic &quot; + tp.file.last_modified_date(&quot;yyyy-MM-dd&quot;)%&gt;"/>

Where does output go, and where are errors reported?

For how output and errors are handled, see Executing scripts.


Next: URI items

Learn more: Executing scripts

⚠️ **GitHub.com Fallback** ⚠️