Templates for quotes and recurrent tasks in Obsidian
4 minutes read | 752 words by Ruben BerenguelI have been using templates to add recurrent tasks to my daily journal in Obsidian.
This won’t be long, and should be easy for Obsidian nerds. I combine two plugins:
- Templater, to have powerful templates. Make sure to read how to use it (TL;DR: create files in a template folder you configure only for the plugin, and this is important).
- Calendar, to have an easy way to go to today or any day.
Additionally, it can be useful to have the Periodic Notes plugin: it is from the same author as Calendar, and lets you have weekly, monthly and even quarterly “master notes”.
The only additional setup you need is enabling Trigger Templater on new file creation
, so the template runs when you create a daily note. Beware, if you write “pseudo-templates” in the wrong directory, they will be ruined by this setting.
My master “journal” template file looks like this:
---
title: "???"
slept:
energy:
---
<% tp.file.include("[[Random-quote-template]]") %>
### Plan
<% tp.file.include("[[Sunday-template]]") -%>
<% tp.file.include("[[Saturday-template]]") -%>
<% tp.file.include("[[Monday-template]]") -%>
<% tp.file.include("[[Tuesday-template]]") -%>
<% tp.file.include("[[Wednesday-template]]") -%>
<% tp.file.include("[[Thursday-template]]") -%>
<% tp.file.include("[[Specific-days-template]]") -%>
- [ ]
#journal
I track (approximately) how much I have spent in bed and how energetic I felt in the morning in the metadata of the file. The file has only the current date, and I usually add a “fun” or descriptive title (like “The day all jobs failed”) to remember better what happened.
All these include
statements are from Templater’s internal methods, these inline all these files. Each one is a template on its own, with Random-quote
being, probably, the most useful:
<%*
let tf = app.metadataCache.getFirstLinkpathDest("Daily quote", "")
let contents = await app.vault.read(tf)
let nonEmpty = contents.split("\n").filter(c=>c!="")
let randomQuote = nonEmpty[Math.floor(Math.random()*nonEmpty.length)]
-%>
> <% randomQuote %>
This template uses the internal Obsidian API as exposed from Templater, finding a file named Daily quote
, reading it and picking a (non-empty) line from it. It then adds it as a quote.
The other templates are specific repetitions: things I may want to do on particular weekdays, or on particular days of the month.
For example, Monday:
<%* if (tp.date.now("ddd", 0, tp.config.active_file.basename, "YYYYMMDD") == "Mon") { -%>
- [ ] Check all tickets
<% tp.file.include("[[Random-article-template]]") -%>
<%* } -%>
This is just a reminder to check the backlog and current sprint, as well as add a post from my list of pending-posts-to-read (those you see from time to time in Readings). That one filters only “task elements”, since I also have Tracker graphs in my pending lists (if you are curious ask me on twitter).
The magic incantation on the first if
is parsing the created file name, and formatting it as day-of-the-week. If the format you use in the Calendar plugin is not YYYYMMDD
you need to change this.
The “specific days” template looks like this:
<%* if (tp.date.now("D", 0, tp.config.active_file.basename, "YYYYMMDD") == 28) { -%>
- [ ] Adjust account balances
- [ ] [Bonus.ly](bonus.ly)
<%* } -%>
So far I only have a recurrent thing on the 28th, to check bank accounts (before bills arrive) and to spend any remaining “magic coins” from Bonus.ly
Finally, another useful trick is alternating weeks, which I run on Sunday, for example:
<%* if (tp.date.now("ddd", 0, tp.config.active_file.basename, "YYYYMMDD") == "Sun") { -%>
- [ ] Readings post?
<%* if (tp.date.now("w", 0, tp.config.active_file.basename, "YYYYMMDD") % 2 == 1) { -%>
- [ ] Recharge Anker headphones
- [ ] Recharge B&W headphones
- [ ] Water plant
<%* } else { -%>
- [ ] Recharge trackball
- [ ] Clean keyboard
<%_ } -%>
<% tp.file.include("[[Random-video-template]]") %>
<% tp.file.include("[[Weekly review checklist]]") -%>
<%_ } -%>
If it’s Sunday, I may write the Readings post, watch a random (probably techie) video and also do a GTD-style weekly review. But on alternating weeks I will recharge all my headphones (and water the plant I have close to my work desktop) or clean and recharge trackball & keyboard.
This is not 100% ideal, since it will wrap-around badly on years with an odd number of weeks, but this is not that critical, and I can just change the template if needed before year’s end.
-%
(or %-
) is one of the several commands used to control whitespace around templates in Templater (see Section Whitespace Control in the documentation). This one in particular removes a newline after the template (or before). I use it to make sure task lists have no extraneous empty lines among them.