diet-okikae.com

Mastering Obsidian Templater Functions for Enhanced Productivity

Written on

Chapter 1: Introduction to Obsidian Templater Functions

Templates can be incredibly beneficial for improving your productivity and efficiency. They provide a ready-made structure and format that can help you conserve time and energy. While Obsidian offers a basic template plugin, the Templater community plugin is a more sophisticated and robust alternative.

This plugin empowers you to incorporate variables and functions into your notes, automating many manual tasks. This can lead to a highly effective workflow that streamlines your processes. In this article, we will explore some of the most valuable Templater functions available in Obsidian. The functions discussed will vary from basic to more complex, compiled from Templater's documentation, Reddit discussions, and the Obsidian Forum.

Section 1.1: Automating Note Organization

Are you tired of manually sorting your notes into various folders? Why not let Templater handle it for you? Use the following function to automatically move notes:

<% await tp.file.move("/002 RESOURCES/" + tp.file.title) %>

This will transfer your note into the "002 RESOURCES" folder in your vault.

Section 1.2: Adding Daily Inspiration

Looking to kick off your day with some motivation? This function can insert a new quote into your daily note from the web:

<% tp.web.daily_quote() %>

Subsection 1.2.1: Incorporating Visuals

Want to include a visual element in your notes? This function allows you to add a random image from the web:

Just a random picture: <% tp.web.random_picture() %>

Random picture with size: <% tp.web.random_picture("600x400") %>

Random picture with size + query: <% tp.web.random_picture("600x400", "mountains") %>

Chapter 2: Templater Functions for Daily Notes

These functions can automatically append dates to your daily notes and help navigate between yesterday's and tomorrow's entries, creating a seamless chain of links in the graph view. They can also simplify task queries.

Section 2.1: Date Functions for Daily Notes

To add today's date, use:

<% tp.date.now("YYYY-MM-DD") %>

For yesterday's and tomorrow's dates, use:

Yesterday's date: <% tp.date.now("YYYY-MM-DD", -1) %>

Tomorrow's date: <% tp.date.now("YYYY-MM-DD", 1) %>

Subsection 2.1.1: Future Daily Notes

If you want to create daily notes for future dates, utilize the note's title:

Today's date: <% moment(tp.file.title, "YYYY-MM-DD") %>

Yesterday's date: <% fileDate = moment(tp.file.title, 'YYYY-MM-DD').subtract(1, 'd').format('YYYY-MM-DD') %>

Tomorrow's date: <% fileDate = moment(tp.file.title, 'YYYY-MM-DD').add(1, 'd').format('YYYY-MM-DD') %>

Subsection 2.1.2: Day of the Year

To display the current day of the year, you can use:

<% moment(tp.file.title, 'YYYY-MM-DD').format("DDD[/365]") %>

Chapter 3: Templater Functions for Periodic Notes

These functions are perfect for crafting a structured periodic notes template in Obsidian.

Section 3.1: Weekly and Monthly Navigation

Use the following to track the current week and month:

This week: <%tp.date.now("gggg-[W]ww")%>

This month: <%tp.date.now("YYYY-MM")%>

To move between different periodic notes for weeks and months, use:

Next Week: [[<% moment(tp.file.title, "ww YYYY").add(1, "weeks").format("gggg-[W]ww") %>]]

Last Week: [[<% moment(tp.file.title, "ww YYYY").subtract(1, "weeks").format("gggg-[W]ww") %>]]

Next Month: [[<% moment(tp.file.title, 'YYYY-MM').add(1, 'months').format("YYYY-MM|MMMM YYYY") %>]]

Previous Month: [[<% moment(tp.file.title, 'YYYY-MM').subtract(1, 'months').format("YYYY-MM|MMMM YYYY") %>]]

Chapter 4: Advanced Templater Functions

These advanced functions will enhance your note-taking experience significantly.

Section 4.1: Inserting Metadata

Want to embed the file title as an H1 in your note? Use:

# <% tp.file.title %>

To show the metadata from the note, such as:

alias: This is an alias

type: literature

You can use:

File's metadata alias: <% tp.frontmatter.alias %>

Note's type: <% tp.frontmatter["type"] %>

Subsection 4.1.1: Callout Template

This function allows you to add a callout easily, saving time and effort.

Chapter 5: Enhancing Navigation with a Table of Contents

Navigating lengthy notes can be challenging, but this Templater function creates a table of contents linking to different sections of the note:

>[!SUMMARY]+ Table of Contents

<%*

// Code to generate TOC

%>

Adding a Countdown Timer

This templater function can be used in your daily note to track important dates, simply define the date and event name, and it will display:

<%*

const eventDate = new Date('2023-05-05');

const now = new Date();

const diff = eventDate - now;

const days = Math.floor(diff / (1000 * 3600 * 24));

%><% days %> days until my event!

Chapter 6: Better Management of Kindle Highlights

If you read books outside of the Amazon store on your Kindle, managing highlights can be tricky. This function extracts your highlights and stores them in a new note.

<%*

const editor = this.app.workspace.activeLeaf?.view?.editor;

if(!editor) return;

// Code to extract highlights

%>

Creating a Basic Note Template

A basic note template can aid in organizing your thoughts effectively.

tags: basic, new

aliases:

date created: <% tp.date.now() %>

Incorporating topics, themes, and related notes during creation simplifies future connections and enhances your second brain’s navigation capabilities.

The first video titled "Automate Your Vault With Templater - How to Use Templater in Obsidian" provides an in-depth look at utilizing the Templater plugin to automate your note-taking processes in Obsidian.

The second video, "Obsidian Templater Snippets I Wish I Knew Sooner," shares essential snippets that can enhance your experience with the Templater plugin.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Exploring the Path to Heaven: Insights and Perspectives

Discover various religious views on how to reach heaven, along with the implications of faith and the quest for understanding.

# Pipelines and Their Environmental Threats: A Call for Action

Pipelines pose severe risks to our environment and health. We must push for better regulations and accountability from oil corporations.

Transforming Business Success: Prioritizing Customer Experience

Explore how investing in customer experience can lead to sustainable growth and enhanced corporate success.