Templater plugin Showcase

Please share your Templater plugin templates or Snippets here for all to see…

2 Likes

This Templater snippet was largely written by fellow forum member @shabegom. Thank you, Shabegom.

The purpose of the snippet is to move yesterday’s Daily Note to a storage folder (PAST) when Obsidian starts up each day. It was becoming a nuisance to move the old daily notes to storage.

This could be made to work, with minor code changes, for any recurring note that you want to move to some other folder.

You wouldn’t know unless you looked at the settings, but Templater was recently updated and the latest version allows you to create a separate template with code snippets only which then run on Obsidian startup. Exactly like a startup script.

So I took the below “move/rename old notes to storage” snippet out of my daily note template and put it in a separately named template, and then pointed Templater to that new startup template. This way my Daily Note stays clean and doesn’t have empty ```s left over after the snippet runs.

Basically, Templater is becoming Obsidian Scripting. Its very cool, I open Obsidian, I see yesterday’s note disappear(renamed/moved to PAST folder) and today’s daily note pops into existence in the same place.

Only caveat, is that you have to use the full path within your Vault, so I have a “001 DAILY” folder where my Daily Notes are created, and within that folder I have another storage folder called PAST. Please change the path to your particular situation or you will receive an error.

Also, I am moving/renaming a note with a Date for a note title - you can see that in the first two lines. Your situation will be different if your Daily Notes use a different title name or date format.

The script only moves yesterday’s daily note, it doesn’t look for older dates. This is only an issue when you open Obsidian after not using it for a weekend say. You might have to move a few notes to storage to get back on track.

If someone wants to enhance the script, please feel free and post your working results here.

```
<%*
const date = tp.date.now(“YYYY-MM-DD”,-1)
const file = tp.file.find_tfile(date)

if (file) {
const name = file.basename
await app.fileManager.renameFile(file, `001 DAILY/PAST/${name}.md`)
}
%>
```

2 Likes

A suggestion snippet for an template

creation-date: <% tp.file.creation_date() %>
author:
source:
aliases:
status:
type:
tags:

< Modification Date: <%+tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %> >

<% tp.file.title %>

References

It will render like this using the Blue Topaz Theme

For a lot of notes I write a short definition summary in the frontmatter.

cardtitle: "Confirmation Bias"
definition: "A [[Cognitive Bias|bias]] describing the tendency to *search for or interpret information in a way that confirms one's preconceptions*."

Note, that markdown is possible in the YAML values.

As I am using the Minimal theme, it allows me to show those as cards, and I also have a note which displays a random definition in my right sidepane.

But now to the templater part. I have developed a template, which uses the dataview API. It allows to search for a definition, will then show the found cardtitles in a list, and on selection, create a callout on cursor position.

Use-case: In note about “topic A” i want to reference to related “topic B” .
The template not only creates a link to “topic B”, but also shows a definition of “topic B” in “topic A”.

Short example video: here

The Templater script:

<%*  
const dv = this.app.plugins.plugins["dataview"].api;

let keyword = await tp.system.prompt("Look up Definition Card","",true,false);
keyword = keyword.toLowerCase();

let query = dv.pages()
	.where(page => page.cardtitle)
	.where(page => page.cardtitle.toLowerCase().includes(keyword));

if (query.length > 0) {
	let choice = await tp.system.suggester(query.cardtitle, query.cardtitle,  false, "Card Title", 30); 

	if (choice) {
		let result = dv.pages()
			.where(page => page.cardtitle == choice);
	
		card = '[[' + result[0].file.name + '|' + choice + ']]';
		tR += '>[!summary] ' + card + '\n>' + result.definition[0];
	}
} 
%>
1 Like