Templater plugin (1.5 and newer): New Syntax and Examples

Can anyone tell me how to make this as days,hours format?
My current one returns only days.

Month ends in: <%+* let edate = moment(“2022-09-30”, “yyyy-MM-DD”); let from = moment().startOf(‘day’); edate.diff(from, “days”) >= 0 ? tR += edate.diff(from, “days”) : tR += edate.add(1, “year”).diff(from, “days”) %> days

Does anyone know how I would set it up to give me a date for the end of the year in 3 years?
so 2025-12-31?

How would I get a date that happens every 28 days? In other words, I have something I have to do every 28 days. Ideally, the output would be MM-DD-YYYY. I want to incorporate it into my daily notes.

I’d use the Tasks plugin

2 Likes

Thank you, no clue, why I hadn’t thought of that since I use it regularly. I was overthinking.

Hi @musa, and all,

Blockquote
I’m looking to dynamically link all the months in a quarter, depending on the quarter.

As I was browsing through this terrific thread (I saved almost all code as snippets, as my JS is still extremely vanilla and I am eagerly learning to apply templater), I encountered your query.

Although it’s been a while, and you yourself must have found your answer long ago, there was a reply from @Saorsa if you had figured this out. I wanted to know too, and have been tinkering with it this afternoon. So for posterity, and hopefully to be enhanced by the more experienced ppl here, a fragment of my Daily Note template:

<%*
let titleName = tp.file.title

if (tp.file.title.startsWith("Untitled"))
titleName = await tp.system.prompt("Note Title")
await tp.file.rename(titleName)

let mnth = tp.date.now("MM-MMMM", 0, tp.file.title, "YYYY-MM-DD");
let yr = tp.date.now("YYYY", 0, tp.file.title, "YYYY-MM-DD");
let qrt = tp.date.now("[Q]Q", 0, tp.file.title, "YYYY-MM-DD");
let folderName = qrt

const dir = "/Journal/" + yr + "/" + folderName + "/" + mnth + "/"
	if (!tp.file.exists(dir)) {
		await this.app.vault.createFolder(dir)
	}
await tp.file.move(dir + titleName);
-%>
---
title: <% titleName %>
creation_time: <% tp.date.now("YYYY-MM-DD, HH:mm") %>
tags: <% tp.file.cursor() %>
type: daily note
---
# <% moment(tp.date.now("dddd, DD MMMM YYYY", 0, tp.file.title, "YYYY-MM-DD")).locale('nl').format("dddd DD MMMM YYYY") %>
<< [[<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>]] | [[<% tp.date.now("YYYY-MM-DD", +1, tp.file.title, "YYYY-MM-DD") %>]] >> 

<% tp.web.daily_quote() %>

![Weather](https://wttr.in/Leiden.png?I0&background=ffffff)

The bit after the frontmatter I included bc maybe someone like to use it, too. There’s a lot more going on, and as you can see, I’m using some local formats, change to your need (the weather, the date format).

And thank you all again for this great thread, and all contributions of the usual suspects here on the forum! I’m forever encountering things I want to improve, and almost always there is someone smart here that has an elegant solution. Someone is always beneftting from the knowledge and skills. :handshake:t3:

Hello all! Wondering if I could use any Templater syntax + Dynamic command function to make a template, which will automatically generate links to the note before it and the note after it within the same folder? :thinking:

A fun little one I just did to get nicely formatted Obsidian forum links into my notes.

An example using this thread:

And the output (with the thread created date):

<%*
let link = await tp.system.prompt('Enter the Obsidian forum link')
// Strip the thread URL to just the numeric thread ID
link = 'https://forum.obsidian.md/t/' + link.match(/\/t\/.*?\/(\d+)/)[1]
try {
  const json = (await requestUrl(link + '.json')).json
  const created = moment(json.created_at).format('MMM D, YYYY')
  tR += `[${json.title}](${link}) (${created})`
} catch (e) {
  console.log(e)
}
%>
3 Likes

Hello @Moonbase59 ,
how is this supposed to work?
When I try the template on a new note with the property “deceased” defined I get the error Unexpected token '*'. If I remove the asterisk I get the error Unexpected token 'if.