A plugin for templating in Obsidian, powered by Nunjucks.
Set the directory that contains the templates to be used inside Settings:

You can insert a new template by clicking on the button in the sidebar

or via the Command Palette

You will be prompted to choose a template if there are multiple defined

Since obsidian-temple uses nunjucks under-the-hood, you can use everything supported by nunjucks. Check the official Nunjucks documentation on how to write nunjucks template.
aliases based on filename with Zettelkasten ID---
uid: "{{ zettel.uid }}"
aliases: ["{{ zettel.title }}"]
tags: []
---
If the filename is 20201224030406 title.md, then the output of the template will be:
---
uid: "20201224030406"
aliases: ["title"]
tags: []
---
It also works if you have the uid as a suffix in the filename, eg: title 20201224030406.md.
zettel is just one of the objects that are provided by obsidian-temple, see Providers for more.
obsidian-temple currently includes a few providers that can provide the context objects for nunjucks:
filezetteldatetimeclipboardCheck their respective documentation at PROVIDERS DOCUMENTATION. You can easily add more providers, see Adding new provider.
You need to:
TITempleProvider<T>For example, for the datetime provider:
DateTimeContextDateTimeTempleProvidermain.tsThis documentation is best viewed inside Obsidian, which can be generated by activating Command Palette > then select Obsidian Temple: Insert documentation of all providers.
fileExposes Obsidian's internal TFile structure for templating.
path: {{ file.path }}
name: {{ file.name }}
basename: {{ file.basename }}
extension: {{ file.extension }}
outputs:
path: Untitled 20210103181939.md
name: Untitled 20210103181939.md
basename: Untitled 20210103181939
extension: md
datetimeReturns the current date and time as Luxon DateTime.
now: {{ datetime.now }}
day: {{ datetime.now.day }}
month: {{ datetime.now.month }}
year: {{ datetime.now.year }}
hour: {{ datetime.now.hour }}
minute: {{ datetime.now.minute }}
second: {{ datetime.now.second }}
outputs:
now: 2021-01-03T22:21:36.585+08:00
day: 3
month: 1
year: 2021
hour: 22
minute: 21
second: 36
dateFormat filterdateFormat uses Luxon under-the-hood for date formatting. For example:
now: {{ datetime.now | dateFormat("ffff") }}
outputs:
now: Sunday, January 3, 2021, 10:21 PM Singapore Standard Time
See Luxon's documentation for a complete list of formatting tokens that can be used.
You can override the default locale and timezone under Settings.
zettelExtracts uid and title from notes that have the Zettelkasten ID.
Given a file named 20201224030406 title.md, the following template
uid: {{ zettel.uid }}
title: {{ zettel.title }}
outputs:
uid: 20201224030406
title: title.md
Works even if the uid is used as a suffix, eg. title 20201224030406.md.
You can override the extraction regex under Settings.
clipboardExtracts data from your system clipboard. Uses sindresorhus/clipboardy.
text: {{ clipboard.text }}
outputs:
text: content