2026-05-02
Templater Plugin for Obsidian Dynamic Templates Guide: Automate PKM
Master the Templater plugin for Obsidian. This dynamic templates guide shows you how to automate note creation, insert dynamic metadata, and build.
Editor summary
I found that the Templater plugin transforms Obsidian from a passive text editor into an active processing engine for personal knowledge management. This dynamic templates guide shows you how to automate note creation using the tp object and execution tags, from simple date insertion to complex JavaScript logic. The key trade-off I observed: while dynamic tags update in reading mode, they can slow performance in large vaults, so execution tags work better for static, one-time generation. By configuring folder-based triggers and avoiding over-prompting, you reduce friction significantly and spend less time managing structure.
Templater Plugin for Obsidian Dynamic Templates Guide: Automate PKM
Quick Answer: The Templater plugin for Obsidian replaces static templates with dynamic, programmable scripts using the
<% tp %>syntax. By executing JavaScript at the moment of note creation, it allows you to automatically insert the current date, fetch external data, rename files, prompt for user input, and route notes to specific folders without manual data entry.
Managing a personal knowledge management (PKM) system often involves repetitive tasks. Every time you create a daily note, log a meeting, or capture a book summary, you likely type out the same structural headings, tags, and date formats. While Obsidian’s core Templates plugin handles basic text insertion, it falls short when you need context-aware data, conditional logic, or automatic file manipulation.
This is where the Templater plugin becomes necessary. Instead of just pasting text, Templater acts as a scripting engine that evaluates code when a template is inserted. It reads the context of your vault, prompts you for missing information, and constructs the note exactly how you need it.
Transitioning from static text to dynamic generation reduces friction in your workflow. When your system automatically handles the metadata, you spend less time managing the structure of your notes and more time focusing on their content. This guide details how to implement dynamic templates, configure advanced scripts, and optimize your Obsidian vault for seamless automation.
Core Concepts of Dynamic Generation
To utilize Templater effectively, you must understand how it processes commands. Templater uses specific tags to distinguish between standard text and code that needs to be executed.
The Syntax Structure
All Templater commands are wrapped in opening <% and closing %> tags. When a template is invoked, the plugin scans the document for these tags, executes the logic within them, and replaces the tag with the resulting output.
There are three primary tag types:
- Execution tags (
<% ... %>): Used for standard commands and outputting values. - Dynamic tags (
<%+ ... %>): Used for commands that should update dynamically every time the file is viewed in reading mode. This is useful for “last modified” timestamps, though heavily relying on dynamic tags can impact performance in large vaults. - Command tags (
<%- ... %>or<% ... -%>): Used to strip whitespace. A hyphen on the inside of the bracket removes the preceding or trailing newline, keeping your markdown formatting clean when using complex conditional logic.
The tp Object
At the center of Templater’s functionality is the tp object. This object contains all the internal modules and functions provided by the plugin.
Key modules include:
tp.date: Functions for retrieving and formatting dates.tp.file: Functions for manipulating the current file, such as renaming it, retrieving its title, or moving it to a new folder.tp.frontmatter: Functions for reading variables defined in the note’s YAML frontmatter.tp.system: Functions for interacting with the user or the operating system, including triggering prompts or retrieving clipboard contents.
Setting Up Your First Dynamic Template
Before writing complex JavaScript, start by replacing static text with dynamic Templater variables. The most immediate benefit comes from automating dates and titles.
Automating Daily Notes
A standard daily note requires the current date, links to the previous and next days, and perhaps a specific layout. Using Templater, you can generate relative dates accurately regardless of when the note is actually created.
Here is a fundamental daily note structure:
# Daily Log: <% tp.date.now("YYYY-MM-DD") %>
<< [[<% tp.date.now("YYYY-MM-DD", -1) %>|Yesterday]] | [[<% tp.date.now("YYYY-MM-DD", 1) %>|Tomorrow]] >>
## Tasks
- [ ]
## Notes
<% tp.file.cursor(1) %>
When triggered, tp.date.now("YYYY-MM-DD", -1) calculates exactly one day before the current date and outputs it in the specified format. The tp.file.cursor(1) command is particularly useful; it places your typing cursor exactly at that location after the template renders, allowing you to start typing immediately without reaching for the mouse.
Meeting Notes with Automatic Metadata
Meeting notes require contextual information: who attended, what the project is, and when it occurred. Instead of typing this manually, you can configure Templater to prompt you for these details upon creation.
---
type: meeting
date: <% tp.date.now("YYYY-MM-DD HH:mm") %>
attendees: <% tp.system.prompt("Who is attending?") %>
project: <% tp.system.prompt("Project name?") %>
---
# Meeting: <% tp.file.title %>
## Agenda
-
## Action Items
- [ ]
When you apply this template, Obsidian will display two text input boxes sequentially. Your answers will be injected directly into the YAML frontmatter, ensuring clean, standardized metadata for future Dataview queries.
Advanced Templater Scripts and Functions
Once you are comfortable with basic variables, you can leverage standard JavaScript within your templates to handle conditional logic and external data.
Using JavaScript for Complex Logic
To write multi-line JavaScript, use an execution tag block combined with an asterisk: <%* ... %>. This tells Templater to execute the code but not to output anything directly unless explicitly instructed via tR += "output string".
Consider a template that changes its greeting based on the time of day:
<%*
let currentHour = parseInt(tp.date.now("H"));
let greeting = "Good evening";
if (currentHour < 12) {
greeting = "Good morning";
} else if (currentHour < 18) {
greeting = "Good afternoon";
}
tR += "# " + greeting + "!";
%>
This block evaluates the hour, determines the correct string, and appends it to tR (Template Result), which represents the final text inserted into your note.
System Prompts and Suggesters
While tp.system.prompt is excellent for freeform text, tp.system.suggester provides a defined list of options. This prevents typos and maintains database consistency, which is critical if you rely on folders, tags, or Dataview.
<%*
const projectTypes = ["Client Work", "Internal Operations", "Research", "Personal"];
const selectedType = await tp.system.suggester(projectTypes, projectTypes);
if (selectedType) {
tR += `Project Category: [[${selectedType}]]`;
} else {
tR += "Project Category: Unassigned";
}
%>
The suggester displays an interactive dropdown menu in the Obsidian interface. This ensures that your Project Category always matches an exact, pre-defined string.
Managing Metadata and Frontmatter
Structured metadata is the foundation of a resilient Obsidian vault. Templater allows you to dynamically construct YAML frontmatter based on file location, creation time, or clipboard contents.
Dynamic File Renaming
Often, you want a note’s file name to follow a strict convention, but typing that convention manually is error-prone. You can instruct Templater to rename the file automatically as soon as the template is applied.
<%*
let baseName = await tp.system.prompt("Enter the core topic:");
let datePrefix = tp.date.now("YYYY-MM-DD");
let newFileName = `${datePrefix} - ${baseName}`;
await tp.file.rename(newFileName);
%>
---
aliases: ["<% baseName %>"]
tags: ["topic"]
created: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %>
---
# <% baseName %>
This template asks for the topic, automatically prepends the date to the file name, renames the file in the file system, and sets up the YAML frontmatter.
Integrating with Dataview
Dataview relies heavily on consistent frontmatter fields. By using Templater to populate these fields, you ensure your Dataview tables never break due to a missing colon or an incorrectly formatted date.
If you capture web articles, you can use Templater to pull a URL from your clipboard directly into a Dataview-compatible field:
---
status: unread
source_url: <% tp.system.clipboard() %>
date_captured: <% tp.date.now("YYYY-MM-DD") %>
---
When you create the note and trigger the template, whatever URL you just copied from your browser is instantly formatted into valid frontmatter.
Practical Implementation Strategies
Writing templates is only half the process; configuring Obsidian to trigger them at the right time is what creates a seamless workflow.
Folder Templates and Automatic Triggers
One of Templater’s most powerful features is the “Folder Templates” setting. This allows you to bind a specific template to a specific folder.
- Open Templater settings.
- Scroll to the “Folder Templates” section.
- Add a new rule: set the target folder (e.g.,
Meetings) and the corresponding template (e.g.,Templates/Meeting Note).
Once configured, any new note created inside the Meetings folder will automatically execute the Meeting Note template. You bypass the command palette entirely. This is highly effective when combined with Obsidian’s core setting to “Default location for new notes,” allowing you to route different note types automatically.
User Scripts for Reusability
If you find yourself using the same complex JavaScript block across multiple templates (such as an API call to fetch weather data), you should abstract it into a User Script.
- Create a folder in your vault named
Scripts. - In Templater settings, set the “User System Command URI” or configure the “User Scripts” folder.
- Write a standard JavaScript file (e.g.,
weather.js) in that folder:function getWeather(city) { // logic to fetch weather return "Sunny, 72F"; } module.exports = getWeather; - Call it in any template using
<% tp.user.weather("Seattle") %>.
This keeps your markdown templates clean and centralizes your code, making maintenance significantly easier.
Practical Advice and Tradeoffs
When deploying Templater at scale, keep the following parameters in mind:
- Avoid Over-Prompting: Using
tp.system.promptis useful, but requiring 5-6 prompts for a single note causes fatigue. Only prompt for essential metadata. Use default values or clipboard integrations for the rest. - Whitespace Management: JavaScript blocks (
<%* ... %>) often leave blank lines in your markdown output. Use the hyphen modifier (<%-* ... %>or<%* ... -%>) strategically to swallow empty lines and keep your final document formatting tight. - Performance Constraints: Relying heavily on dynamic tags (
<%+ ... %>) can slow down Obsidian if you have thousands of files, as the code evaluates every time the note is rendered in Reading mode. Use execution tags (<% ... %>) for static, one-time generation whenever possible. - Error Handling: If a template script fails (e.g., waiting for user input that is canceled), it leaves raw
undefinedor partial code in the note. Wrap complex logic intry...catchblocks within your<%* %>tags to handle cancellations gracefully.
Conclusion
The Templater plugin for Obsidian dynamic templates guide demonstrates that static note creation is an unnecessary bottleneck. By implementing the tp object, configuring folder-based triggers, and utilizing basic JavaScript, you transform Obsidian from a passive text editor into an active processing engine. Start by automating your dates and file names, then gradually introduce system prompts and user scripts to enforce metadata consistency across your entire vault.
Frequently Asked Questions
What is the difference between Obsidian core templates and the Templater plugin?
Obsidian core templates only insert static text and basic date formats. The Templater plugin evaluates JavaScript, allowing you to run conditional logic, prompt for user input, manipulate file names, and pull data from the clipboard or external APIs at the moment of creation.
How do I stop empty spaces from appearing when using Templater logic?
Use the hyphen modifier inside your tags to strip whitespace. For example, <%-* your code -%> will execute the JavaScript without leaving a blank line in your final markdown document.
Can Templater automatically move a note to a different folder?
Yes. You can use the command await tp.file.move("/New/Folder/Path/" + tp.file.title) within an execution block. When the template runs, it will physically relocate the file in your vault based on the specified path.
Why are my Templater commands showing up as raw text instead of executing?
This usually happens if Templater is not configured to trigger automatically on new file creation, or if you apply the template using the core Obsidian command instead of the “Templater: Insert Template” command. Ensure “Trigger Templater on new file creation” is toggled ON in the plugin settings.
Do I need to know JavaScript to use the Templater plugin?
No. You can access 90% of the plugin’s value using built-in commands like <% tp.date.now() %> or <% tp.file.title %>. JavaScript is only required if you want to build complex conditional logic, loops, or integrate external data sources.
Related Reading
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Automating Obsidian Frontmatter with Templater Scripts: 5-Step Guide
-
Applying the PARA Method to an Obsidian Vault: Complete Guide