Say hello to yourself!
## Good <% tp.date.now("dddd") %> Morning Samwise!
You can use tp.date.now
inside a link to create links to your previous and next daily note. The second argument is an offset.
[[<% tp.date.now("YYYY-MM-DD", -1) %>|Yesterday]]|[[<% tp.date.now("YYYY-MM-DD", 1) %>|Tomorrow]]
This is a little bit more complicated, but not by much! This command add a link to a random note from your vault.
The previous commands were opened with <%
. To run javascript inside a templater command we bee the use a <%*
opening.
<%*
What is app
? Open your dev console and type app
into it. Whoa! We have full access to the Obsidian API inside of Templater. This opens up many more possibilities to those brave enough to explore.
app.vault.getFiles()
returns an array of all the files in your vault
const files = app.vault.getFiles()
We're using some basic JavaScript to grab a random element from the array. We're storing the random file to a variable randomNote
. Once you store a variable in a Template, you can reuse it elsewhere
const random = Math.floor(Math.random() * (files.length - 1))
const randomNote = files[random]
By closing a command with -%>
we're telling Templater to not add a blank line where this command was. in the template. Super handy for commands that don't return a value like this one.
-%>
Finally, we grab the randomNote
and create a link to it.
Today's random note is [[<% randomNote.basename %> ]]
If you hit the next link, it won't use your daily notes template. Unless you set that up in the Templater settings!
tp.date.now
includes a few more arguments beyond the format and offset.
tp.date.now
above and change them to be: tp.date.now("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD")
the 0
is your offset so don't forget to use -1
and 1
for the yesterday/tomorrow links.