Help with Templater

I’ve reviewed this thread ( New Properties and templater prompts and commands?) but am unable to get the suggestions to work.

What I’m trying to do

I’ve been using these three properties in my YAML frontmatter for a few years and with the Obsidian properties update they ‘broke’.

Here are the existing YAML/Frontmatter properties:

UID: <% Math.round(((Math.random()1015)(tp.date.now(“YYYYMMwwDDHHmmss”))/(Math.random()*1015))) %>

File Creation Date: <% tp.file.creation_date() %>

modification date: <% tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm:ss”) %>

I’ve spend the last two weeks reviewing the above mentioned thread and am unable to get any of the coding suggestions to work. I’m not a programmer so I’m not quite catching what all is happening in the suggested code examples.

For notes already created, the properties aren’t throwing an error for the UID and File Creation Date properties have a number already listed that was generated by Templater when the notes were created. The Modification date is throwing an error in the Properties editor and is used to drive some Dataview tables in my vaults (I can live without it).

I tried to move the UID, File Creation Date, and modification date properties into the body of the note itself but the UID and modification date properties are still throwing an error when in the Body of the note.

I’d like to keep the UID and File Creation Date in the YAML Frontmatter if possible. The last modification date can live in the body. I can still access if for Dataview to work…

Things I have tried

I attempted to put the three properties into the body of the Template, as a test. File Creation Date is the only one that won’t throw a console error and abort creating a new note.

I believe the main error showing in the console is: “Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘parent’)”

I need some help 'migrating these to the update version of Obsidian and will greatly appreciate any help.

Which errors are you getting exactly? Because besides syntax errors or something like that, I don’t think there should be any issue keeping them as they are.

I get a ‘Template Error: Template parsing error, aborting. Check console for more information’.

I’m not sure which specific error in the console to address.

I’ve been going through existing notes and deleting properties that are showing as errors.

Here is an example of the ones I’m finding and deleting the property that is throwing errors as it will never parse the Templater piece. For this one, the Creation Date never processed, not sure why.

2024-03-16 12_14_13- Obsidian v1.5.8

Most look like this where the properties have already been ‘created’/‘calculated’ and aren’t throwing errors.

2024-03-16 12_15_10-Bear and Badger Pricing structure - Evil Plans And Unicorn Drawings - Obsidian v

Looks like I have errors for the Kindle Notes and Note Refactor plugins as well. Both appear to be placing properties into the Frontmatter.

2024-03-16 12_20_16-Kindle Highlights v1.5.8

I’ve removed the Frontmatter area front he plugin templates but this really kills the usefulness and flexibility of Obsidian and these plugins for creating a data rich note system if the plugins that help automate placing the data don’t work…

Thanks for the screenshots. Can you reshare your template, this time inside a code block?

Here is what I was using prior to the update:

---
UID: <% Math.round(((Math.random()10**15)(tp.date.creation_date(“YYYYMMwwDDHHmmss”))/(Math.random()*10**15))) %>
File Creation Date: <% tp.file.creation_date() %>
modification date: <% tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm:ss”) %>
---

Here is what I have inside the Note Refactor Plugin

---
tags: definition
UID: <% Math.round(((Math.random()*10**15)*(tp.date.now("YYYYMMwwDDHHmmss"))/(Math.random()*10**15))) %>
type: [definition,referenece]
creation date: <% tp.file.creation_date() %>
modification date: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>
---

In attempting to have these live in the body and still use Dataview with them I tried:

UID:: <% Math.round(((Math.random()10**15)(tp.date.creation_date(“YYYYMMwwDDHHmmss”))/(Math.random()*10**15))) %>
File Creation Date:: <% tp.file.creation_date() %>
modification date:: <% tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm:ss”) %>

The Kindle Highlights plugin uses the following but doesn’t appear to have any Frontmatter included.

`# {% if longTitle %} {{longTitle}} {% endif %}

Author:: {{author}}

Author on Amazon:: {{authorUrl}}

Book Image:: {% if imageUrl %} {{imageUrl}} {% endif %}

## Highlights
{% if highlights %}{{highlights}}{% endif %}`

For some of my journaling, I used extensive Frontmatter to allow Dataview to build tables of different date/time snap shots.

---
tags: yearly_reflect
alias: This Week
UID: <% Math.round(((Math.random()*10**15)*(tp.date.now("YYYYMMwwDDHHmmss"))/(Math.random()*10**15))) %>
journal_date: <% tp.date.now("YYYY-MM-DD")%>
journal_week: <% tp.date.now("gggg-[W]ww")%>
journal_month: <% tp.date.now("YYYY-MM")%>
journal_quater: <% tp.date.now("YYYY-[Q]Q")%>
journal_year: <% tp.date.now ("YYYY")%>
type: journal
creation date: <% tp.file.creation_date() %>
modification date: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>
---

Moving this last example to the body of the note did yield the correct processing of the Templater ‘code’:

tags: yearly_reflect
alias: This Week
UID: 2862779816986832
journal_date: 2024-03-16
journal_week: 2024-W11
journal_month: 2024-03
journal_quarter: 2024-Q1
journal_year: 2024
type: journal
creation date: 2024-03-16 13:57
modification date: Saturday 16th March 2024 13:57:59

In comparing it looks like tp.date.now will work in the body of a note. Not sure how to get it to implement into the Frontmatter like I had before. UID worked using it instead of tp.file.creation_date.

In looking further, the Quickadd plugin will also throw errors as the options are in the frontmatter.

Here is an example of a template I use with QuickAdd. I’m guessing that the update to the Frontmatter by the QuickAdd plugin will no longer function.

---
UID: <% Math.round(((Math.random()*10**15)*(tp.date.now("YYYYMMwwDDHHmmss"))/(Math.random()*10**15))) %>
tags: daily_bullet, journal
journal_date: <% tp.date.now("YYYY-MM-DD HH:mm:ss")%>
journal_week: <% tp.date.now("YYYY-[W]ww")%>
journal_month: <% tp.date.now("YYYY-MM")%>
journal_quarter: <% tp.date.now("YYYY-[Q]Q")%>
journal_year: <% tp.date.now("YYYY")%>
type: journal
Bullet Type: {{VALUE:🌈-Something Positive,🔷-Something Unexpected,🦄-Inspiration/Idea,🎭-Read/Watched/Listened to,♻-Purged/Sold/Recycled,💸-Bought,🔮-Dream,🗓️-Event,🍕-Food/Beverage Experience,🗺-Traveled,🦨-Something negative,🎉-Gratitude,✈️-Drone Flying}}
Bullet Entry: {{VALUE:Bullet Entry}}
creation date: <% tp.file.creation_date() %>
modification date: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>
---

Only one template should insert the code fences, the triple dashes, around your frontmatter, so when you present three or four templates with the code fences I’m wondering how you insert your templates. It shouldn’t, and I don’t see how that would ever have worked.

You’re also talking about templates not being updated, which doesn’t really make sense. After you’ve inserted any template, the template text is replaced with pure text, and no changes to the template will affect those notes where that template has already been inserted.

If you want to change frontmatter which has already been inserted/added into a note, you’ll need to use app.fileManager.processFrontMatter or some other plugin which handles that another way. But in general you simply can’t insert multiple frontmatter blocks from multiple templates like you’ve shown here.

All in all, I’m unsure and wondering how do you insert these templates? How do you create the note, and what’s the setup like?

I copied this example into a note and ran Templater’s command “Replace templates in the active file”, and as I expected, everything executed without issue:

Obsidian_S92UUbNSaj

Those little warning signs are just because I haven’t used the property UI to change the property types from text to number.

1 Like

When I compared the working UID from the example I tested, to the UID in this example, which indeed throws an error:

this is what i got:

As you can see, there’s some discrepancies. You can try for yourself on https://text-compare.com/.

The main issue is that you are using instead of " in both the UID and the last modification date. Furthermore, there’s some issues with some missing *.

That’s likely all there is to your troubles. Nothing to do with the new Properties UI.

1 Like

I use a single Template for a note. I have some that I insert into notes, like Star ratings. Those don’t have any Frontmatter on the base template. I use QuickAdd to insert those as it seems to work the best.

This is typically how I setup a journal templates to use:

I use QuickAdd plugin to link the individual trackers onto this template by creating a link to that specific tracker for the day.

I don’t stack templates with Frontmatter.

Here is an example of the end result using QuickAdd to ‘insert’ other notes into my Daily Journal note:

I don’t insert Templater code into an existing Template (nesting templates inside each other). I insert the linked note option to display the other inside notes. I use QuickAdd to prompt me for the answers to fill in. It creates a note and then inserts a link into the ‘parent’ journal note to build a Daily Journal note. I don’t have to keep going back to the same note and adding to it. QuickAdd inserts each piece to the parent note to build it out as I perform a ‘Journaling task’. Filling out a tracker, adding a bullet, etc.

Each Journal note type is kept in a different folder. This way I can use Dataview later to create weekly/monthly/quarterly/yearly summaries. I can query just the Dataview.

2024-03-16 15_40_09-2022-10-31 - Evil Plans And Unicorn Drawings - Obsidian v1.5.8

Thanks for the link to the text compare. I’ve booked marked that for help in troubleshooting.

I don’t understand what you mean by “instead of” used in the properties.

Can you break that down to crayola for me?

I did correct the UID and that is working now, thank you!

Look more closely at the symbols, as I wrote them. They are not the same. The first is a curly quote, the latter is a straight quote. Only the latter works. You need to replace the curly quotes with straight quotes.

Sorry for missing that. I was thinking “instead” of what some combination of symbols or the way I had setup the code, like order of operations. :rofl:

I think the curly vs straight quotes is just a matter of where I’m typing them and the font. I don’t have a specific way to choose either as far as I know. In Obsidian they appear to be straight quotes in the Frontmatter and curly when I switch to a Reading view due to the font.

If you are using an iOS device, there could be some autocorrection going on, see “smart punctuation”.

I primarily use a Windows Desk or Laptop. Occasional I’ll look at tasks on my Android phone but usually not enter anything. Sometimes check ones that are done.

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