Templater

All things related to Templater

Notes

Guides

My Scripts

Temporal

Cursors

<%tp.file.cursor(1)%> this one immediately gets replaced by cursor if the number is 1

additional ones denoted by number order you must "Tab" through with the templater keybinding which i have mapped to ⌥+Tab

<%tp.file.cursor(2)%>

Prompts

<%tp.system.prompt("What is my name", "TOPHER")%>

Logic / Control Flow

Basically JavaScript Functions:

if (tp.file.tags.contains("#todo")) {
	"This is a todo file !"
} else {
	"This is a finished file !"
}
<%* if (tp.file.tags.contains("#todo")) { %>
This is a todo file !
<%* } else { %>
This is a finished file !
<%* } %>
can also use `else if`

```javascript
<%* if (1==2) { %>
if result
<%* } else if (1==1) { %>
else if result
<%* } else { %>
else result
<%* } %>

Can also use arbitrary JavaScript:

<%* if (tp.file.title.charAt(0) == "{") { %>
<%tp.file.cursor(1)%><%tp.file.include("Templates/Inputs/Book")%>
<%* } else if (tp.file.title.charAt(0) == "=") { %>
<%tp.file.cursor(1)%><%tp.file.include("Templates/Inputs/Thought")%>
<%* } else { %>
<%tp.file.cursor(1)%><%tp.file.include("Templates/Inputs/New")%>
<%* } %>

in here the result of the tp api is getting the file name to the tp.file object that has a property .title so we're getting the first character of that title with pure Javascript through: .charAt(0)

putting it all together: tp.file.title.charAt(0)

Examples

SilentVoid13/Templater · GitHub - GitHub Repo of Templater examples including:

Choose Folder and create file by template

When creating a note with this in the template it will prompt for a folder and title

<%*
const folders = this.app.vault.getAllLoadedFiles().filter(i => i.children).map(folder => folder.path);
const folderPath = await tp.system.suggester(folders, folders);
const title = await tp.system.prompt("Title")
await tp.file.rename(${title})
await tp.file.move(/${folderPath}/${title})
%>

Rename and move file to specific folder

<%*
//If File is untitled prompt the User to set a Title (Source: https://github.com/SilentVoid13/Templater/discussions/259)
let title = tp.file.title
if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Title") ?? "Untitled";
    await tp.file.rename(`${title}`);
} %>
date: "<% tp.file.creation_date("dddd Do MMMM YYYY HH:mm") %>"
topic: <% tp.file.cursor(1) %>
tags:
  - <% tp.file.folder() %>/<% tp.file.cursor(1) %>
aliases: []
<%*
//If this File is in my English Folder set the language correctly. I assume it will be German otherwise
//This is mostly for the Dictionary Plugin Integration
if(tp.file.folder() === "Englisch") {
	tR += "language: en-US";
} else {
	tR += "language: de";
} %>
---

# <% tp.file.title %>

<% tp.file.cursor(2) %>

up:: Tools + Plugins