8

https://dannb.org/blog/2022/obsidian-daily-note-template/

 1 year ago
source link: https://gist.github.com/dannberg/48ea2ba3fc0abdf3f219c6ad8bc78eb6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Dann Berg's Daily Note Template for Obsidian. Uses Dataview & Templater plugins. Should be saved as a Markdown file in Obsidian. Read the full tour

Instantly share code, notes, and snippets.

Dann Berg's Daily Note Template for Obsidian. Uses Dataview & Templater plugins. Should be saved as a Markdown file in Obsidian. Read the full tour: https://dannb.org/blog/2022/obsidian-daily-note-template/

I just confirmed in my Obsidian that it's working just perfectly for me with double-quotes rather than single-quotes around YYY-MM-DD. I wonder where the difference is that's causing it to break for you but work for me.

For me, it worked fine too. Only the template showed an Dataview Error, that you can fix with single quotes.

Oh and I added an <% tp.file.cursor() %> to the Notes Section, so you can start writing, when Obsidian starts with your daily note.

Thank you very much for this very great template!

Author

Oh and I added an <% tp.file.cursor() %> to the Notes Section, so you can start writing, when Obsidian starts with your daily note.

That's a cool trick! I didn't even know that existed. I'm going to update the gist, and start using that myself, too.

sry if thats a supid question, but does +Daily Notes do anything? or is it just the name of the file that you link all your daily notes to?

Thanks for sharing!

To make this work you have to enable some options in Templater.

I enabled the following:

  • Automatic jump to cursor
  • Trigger Templater on new file creation

Hello. I'm trying to build my personal obsidian vault. While doing research, I came across this page and ran into a problem. With tp I get the value of the previous and next day. But when I click on it, I encounter the problem in the picture below.

image

image

Author

Hello. I'm trying to build my personal obsidian vault. While doing research, I came across this page and ran into a problem. With tp I get the value of the previous and next day. But when I click on it, I encounter the problem in the picture below.

@mt190502 It looks like the Templater plugin is not firing when the new page is created. Templater should turn the <% %> tags into text, and it looks like that's not happening here. I'd review your settings in the Templater Plugin settings screen? Not 100% sure where the error is, but that's where I'd check first.

Hello. I'm trying to build my personal obsidian vault. While doing research, I came across this page and ran into a problem. With tp I get the value of the previous and next day. But when I click on it, I encounter the problem in the picture below.

It looks like the Templater plugin is not firing when the new page is created. Templater should turn the <% %> tags into text, and it looks like that's not happening here. I'd review your settings in the Templater Plugin settings screen? Not 100% sure where the error is, but that's where I'd check first.

Thank you very much for your interest. After hours of research, I solved the problem <3

Author

Thank you very much for your interest. After hours of research, I solved the problem <3

Do you remember how you solved it? It might be useful to share here in case future people have the same issue.

Thank you very much for your interest. After hours of research, I solved the problem <3

Do you remember how you solved it? It might be useful to share here in case future people have the same issue.

Of course. First of all, I created the "_templates" folder in the main directory and created my templates. I selected the folder first in Settings > Templater. Then I opened the 'New File Creation Trigger' option and connected the templates to the folders as in the photo below. I ran into a few syntax errors. It worked when I fixed them too

image

Author

Just updated the Yesterday/Tomorrow links to use Templater's moment() function. The old code would have broke if creating daily notes for the future.

From Lopyter on Reddit:

As they are right now, the links will be broken if you ever decide to create a day's notes before the actual date. If you want to plan the day for tomorrow, the "yesterday" link in the note will link to today's yesterday (so 2 days ago from the note's POV) and the "tomorrow" link will link to the actual note itself. Not very useful and a potential point of confusion/frustration down the line.

I noticed it didn't work when using another Date Format in the settings of Daily Notes (I used DD MMM, had to remove it)

Author

I noticed it didn't work when using another Date Format in the settings of Daily Notes (I used DD MMM, had to remove it)

Good call. You should be able to update the Templater code to mirror the Date Format you prefer. I should add a disclaimer to the blog post. Thanks.

Rot4n

commented

Nov 4, 2022

edited

For daily notes that are created in the past or future it would be better to determine the date from filename instead of current date. Here's how I did it:

For created notes:

list from "" where file.cday = date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>") sort file.ctime asc

And for modified notes (excluding created notes of the same day as suggested by @Steellow ):

list from ""
where
  file.mday = date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>")
  and 
  file.cday != date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>")
sort file.mtime asc

The moment(tp.file.title,"YYYY.MM.DD") part indicates that moment() should read the file title in "YYYY.MM.DD" format, which is the one I use, so adjust accordingly.
Could be useful for tomorrow/yesterday links as well.

I hope it might be useful to someone.

Has anyone solved the "issue" when you try to jump from a Monday to a Friday?
Is there a smart way one could script so that it finds the closest existing note?

@Aron-Polner oof, don't take my word for it, but you could create a user functions like previousDate() and nextDate(), pull in moment-business-days using unpkg in your custom defined functions, and then add them to the tp.date object (this object IS the moment object source).

This should enable you to use them in your template accordingly to get that wrap around. I suspect it'll slow down templater launch on first go, however. YMMV

Not a real coder here - I've got

  • the templates enabled
  • the settings switched on I believe
  • and a new empty daily note in the templates folder as the instructions say

but where exactly do I paste the raw template code here?

I'm guessing I just paste it into the empty template note in source mode, but for me

<% moment(tp.file.title,'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>

still shows up coded rather than the date

and I get this in the bottom sections

Notes created today
Dataview: Error:
-- PARSING FAILED --------------------------------------------------

1 | List FROM "" WHERE file.cday = date("<%tp.date.now('YYYY-MM-DD")%>") SORT file.ctime asc
| ^
2 |

Expected one of the following:

'(', 'null', boolean, date, duration, file link, list ('[1, 2, 3]'), negated field, number, object ('{ a: 1, b: 2 }'), string, variable
Dataview: Error:
-- PARSING FAILED --------------------------------------------------

1 | list from "" where file.cday = date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>") sort file.ctime asc
| ^
2 |

Expected one of the following:

'(', ')', '*' or '/' or '%', '+' or '-', ',', '.', '>=' or '<=' or '!=' or '=' or '>' or '<', '[', 'and' or 'or'
Notes last touched today
Dataview: Error:
-- PARSING FAILED --------------------------------------------------

1 | List FROM "" WHERE file.mday = date("<%tp.date.now('YYYY-MM-DD")%>") SORT file.mtime asc
| ^
2 |

Expected one of the following:

'(', 'null', boolean, date, duration, file link, list ('[1, 2, 3]'), negated field, number, object ('{ a: 1, b: 2 }'), string, variable

I also had same problems as @chump 's.

Dataview: Error: 
-- PARSING FAILED --------------------------------------------------

  1 | 
> 2 | List FROM "" WHERE file.cday = date("<% tp.date.now("YYYY-MM-DD") %>") SORT file.ctime asc
    |                                                      ^
  3 | 

Expected one of the following: 

'(', ')', '*' or '/' or '%', '+' or '-', ',', '.', '>=' or '<=' or '!=' or '=' or '>' or '<', '[', 'and' or 'or'

Author

@jiwonsim @chump I see a "parsing failed" error when viewing the Daily Note Template post itself. When you create a new note using that template, with the Templater plugin working correctly, it should parse the code correctly in the new note that was created from the template.

I figured out the issue with dataview - when i was pasting the code, for some reason it was creating some extra spaces. However @dannberg I'm still for some reason having issues with this part of the code

# <% moment(tp.file.title,'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>
It's not just yours though, other templates where moment used weren't working for me, although the yesterday/tomorrow part works oddly.

This is the first time I am playing with this, but I think if you add a "+" after the % like this:

# <%+ moment(tp.file.title,'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>

Wow!! That did it. I'm confused as to why that works? I don't see the + in anyone's sample codes. major thanks for solving that one for me @Claustn I've been racking my brain for days on it.

Author

That's so strange. I have no idea what the + does there, but I'm glad you got it working!

If anyone reading this knows why some people need a + and others don't, let me know and I can update the post.

I was missing the tasks that I've not completed from other days and modified the template a bit! If you think it'd be useful...

##### 🚀 Thing(s) from other days that I need to finish
```
dataviewjs
 dv.taskList(dv.pages('"Timestamps"').file.tasks.where(t => !t.completed && t.text != ""));
```

Just noticing that the section for "Notes created today" uses the current date, so if you create a note for a day in the future or past, it won't give the correct info. I sometimes create future or past notes for upcoming info or if I missed a day. Is there an easy way to update this?

I am just staring out with Obsidian and came across this great template. However, I also followed the suggestion of storing daily notes in "Timestamps/Year/Month/Day", in which case the Yesterday and Tomorrow buttons don't quite work (they create a file in the root directory and without the template. I solved it by updating the code for the tomorrow button as follows:

fileDate = moment(tp.file.title, 'YYYY-MM-DD-dddd').add(1, 'd').format("[Timestamps]/YYYY/MM-MMMM/YYYY-MM-DD-dddd")

and similarly for the yesterday button. Then in the Templater settings, under "Folder Templates", I added the "Timestamps" folder with the daily note template (wherever it is stored for you). Now, when creating new notes with the yesterday and tomorrow buttons, it seems to work, hopefully this will help someone with the same problem.

I will now look for easy ways to create a note for an arbitrary day but at worst you can just create a new note with the date in the title.

@szhydkov thanks! I had the same issue and that solved it perfectly!

I am just staring out with Obsidian and came across this great template. However, I also followed the suggestion of storing daily notes in "Templates/Year/Month/Day", in which case the Yesterday and Tomorrow buttons don't quite work (they create a file in the root directory and without the template. I solved it by updating the code for the tomorrow button as follows:

fileDate = moment(tp.file.title, 'YYYY-MM-DD-dddd').add(1, 'd').format("[Timestamps]/YYYY/MM-MMMM/YYYY-MM-DD-dddd")

and similarly for the yesterday button. Then in the Templater settings, under "Folder Templates", I added the "Timestamps" folder with the daily note template (wherever it is stored for you). Now, when creating new notes with the yesterday and tomorrow buttons, it seems to work, hopefully this will help someone with the same problem.

I will now look for easy ways to create a note for an arbitrary day but at worst you can just create a new note with the date in the title.

I had the same problem with yesterday and tomorrow dates that don't yet exist and this solved it, thanks so much!

For folks who have a daily note with a non date name, or in a non US format, rather then using:
# <% moment(tp.file.title,'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>
Which uses the file title for date formatting you can use:
moment(tp.file.creation_date(),'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>
This allows you to name your Daily Notes in anyway you see fit (In my case I use a different date format with some extra characters), instead it takes the date the file created instead.

Which means now my daily notes are not from # Wednesday, January 20, 2021 laughing


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK