Nested templates utilizing the Templater plugin

I only recently discovered Obsidian, its plugins and the very active community surrounding it. I’m impressed and excited, to say the least. I’ve worked with quite a few note taking systems in the past. Never have I felt so confident that this might be the solution that will cover all my needs, in my personal as well as my professional life.

I would like to ask for advice for a specific use case with the Templater plugin. I’d like to create a few small “base” templates which will serve as building blocks for note templates. I.e.:

I have a fileDateInfoTemplate that utilizes the DataView plugin to display a note’s creation and modification date. It consisted of one line of code:

<sub>==Created:==&nbsp; `$= dv.current().file.ctime`&nbsp; ⋯ &nbsp;==Modified:==&nbsp; `$= dv.current().file.mtime`</sub>

Example output:
image

I reuse the fileDateInfoTemplate in my DailyNotes template. Excerpt:

---
tags: DailyNote
---

<% tp.file.include("[[fileDateInfoTemplate]]") %>
<sub>==Prev. Daily:==`="&nbsp; [[" + dateformat(this.file.cday - dur(1day), "yyyy-MM-dd") + "]]"`&nbsp; ⋯ &nbsp;==Next Daily:==`="&nbsp; [[" + dateformat(this.file.cday + dur(1day), "yyyy-MM-dd") + "]]"`</sub><br><br><br>

# `$= dv.current().file.name`

In the first line following the Frontmatter section Templater allows me to include the fileDateInfoTemplate into my DailyNote template. Output:

image

Above is the desired outcome, which I receive as long as I insert the DailyNote template with Templater into a note.
When I use the (Obsidian core) Daily Note plugin to create the DailyNote, the tp.file.include method is not resolved though, resulting in this:

image

I guess this is expected behavior since Templater is not involved when creating the Daily Note with the core Daily Note plugin? Is there a workaround to resolve the tp.file.include() even when the Note is not created by Templater?

Thanks!

3 Likes

Sometimes writing down a problem helps to find a solution. :slight_smile:
In this case it was a rather easy one: make Templater listen to the Obsidian New File Creation event. In the Templater settings dialog:

Once this option is enabled, in the note embedded Templater commands get resolved during note creation.

Also, for reference, Templater has a hotkey to replace all templates in the active file. I use the hotkey if I create a file and the Templater commands do not resolve.

Here is a screen capture

2 Likes

Thanks, that’s good to know. I love how flexible Obsidian and its template system is.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.