This plugin adds commands to create notes based on template files. It will go through each file in the templates
directory in the settings, and create a command 'From Template:
Discussion thread on Obsidian Forum: https://forum.obsidian.md/t/plugin-create-notes-from-templates/23452
An example template file might be:
---
template-output: People
tags: person, {{tags}}
template-replacement: "[[{{title}}]] ![[{{title}}#^overview]]"
template-input: title, overview, body
template-should-replace: "sometimes"
template-should-create: "open-pane"
---
# {{title}}
{{overview:area}}
^overview
Organisation: {{organisation}}
{{body}}
This would
Templates can contain YAML fields that will be filed out in the same way as the rest of the template and become part of the note's Properties. So this will work as expected:
---
organsiation: "{{organisation}}"
---
{{name}} works at {{organisation}}
In order to be proper YAML, values cannot start with {
or they are treated as dictionaries, so make sure to use organisation: "{{org}}"
rather than organisation: {{org}}
in the frontmatter.
For List properties, it will try to be clever if you make the property a List in the template. So you can have a template like this:
tags:
- template-test
- "{{tags}}"
and if you put extra-tag, another-extra-tag
in the input field, it will render as:
tags:
- template-test
- extra-tag
- another-extra-tag
(these will all be filtered out of the rendered note)
Name | Value | Default |
---|---|---|
template-id | Unique ID for the template | Lowercase version of the base name |
template-name | Name for the command | Base name of the file |
template-output | Directory to save the output | test |
template-filename | Filename for the created note. Will have .md appended. Note: if you set a different filename, then make sure to use {{filename}} in the template-replacement strings if you want to link to the file. |
{{title}} |
template-replacement | A Mustache template to replace the selected text in the editor with. Can pass a list, which will appear as buttons in creator | {{[[title]]}} |
template-input | If the command is called with some text selected, split it up using the plugin's split pattern, and put the values into those fields | title,body |
template-should-replace | Should the template write text back to the document? "always", "sometimes" = only if text is selected, "never" | "sometimes" |
template-should-create | Should the template make and open a note? "none"=no note, "create"= create but don't open, "open"=create and open in current editor, "open-pane" = create and open in new pane, "open-tab" = open in new tab | "open-tab" |
template-filename: "{{title}} - autocreated"
template-replacement: "{{title}} - ![[{{filename#^overview}}]]"
template-should-create: "none"
template-should-replace: "always"
template-replacement: "{{templateResult}}"
Each field is double curly braces, a field ID, a field type (defaults to text), some number of arguments separated by :
and optionally a description after a |
, i.e. {{fieldID:fieldType:arg1:arg2|This is an example field}}
Type | Args | Description | Example(s) |
---|---|---|---|
text | none | A text input field - this is the default | {{name}}, {{country:text}}, {{country:text:Belgium}} |
area | none | A text area - default if the field name is 'body' | {{description:area}}, {{body}} |
currentDate | format | The current date, using the format in Luxon format (https://moment.github.io/luxon/#/formatting) (Moment.js shouldn't be used for new projects, dayjs doesn't play nicely with the build system) | {{now:currentDate:dd-MM-yyyy}} |
choice | choices | A dropdown select field | {{suit:choice:hearts:spades:diamonds:clubs}} |
multi | choices | A multi-select field | {{colors:multi:yellow:red:green:blue}} |
Field | Description | Usage Example |
---|---|---|
currentTitle | The title of the active note when the template was triggered | parent: [[{currentTitle}]] in frontmatter to create hierarchy |
currentPath | The path of the active note when the template was triggered |
Some hotkeys are defined:
Very open to collaboration - drop me a line or PR
hh\:mm\:ss
for a time value)|
character, e.g {{field|description}}
which will be shown in the template UI.tags
field will suggest existing tags, and other fields will suggest internal links if [[
is entered.{{properties}}
in template-output
(e.g. template-output: Projects/{{project}}
to put files in project directories)multi
field type to allow a multi-select with toggles{fieldname:text:default:description}
or {fieldname:area:description}
currentdate
field type, e.g. {{now:currentdate:dd-MM-yyyy}}
currentPath
and currentTitle
field names, e.g. [[{{currentTitle}}]]
to link back to current note
{{suit:choice:hearts:spades:diamonds:clubs}}
template-filename
in the template. Defaults to {{title}}
, but all template fields available.template-replacement
, then these will all be options in the template dialogBig changes - completely refactored, new options, new fields, most defaults in settings, should be more responsive to template changes