Daily note template based on day of the week

Language:: JavaScript
Program:: Obsidian
Link:: Daily note template based on day of the week (bonus: link note to current day) ยท Discussion #240 ยท SilentVoid13/Templater ยท GitHub

Summary

Daily note template based on day of the week, see discussion for more details and use cases

Code

I wanted a solution to populate different Day Planner schedules based on the current day of the week, and with some help from @shabegom I have achieved this with the following:

User JS scripts:

scheduleTemplate.js

function scheduleTemplate(tp) {
  switch (parseInt(moment(tp.file.title).format('d'))) {
    case 1: return tp.file.include("[[Schedule - 01 Monday]]")
    case 2: return tp.file.include("[[Schedule - 02 Tuesday]]")
    case 3: return tp.file.include("[[Schedule - 03 Wednesday]]")
    case 4: return tp.file.include("[[Schedule - 04 Thursday]]")
    case 5: return tp.file.include("[[Schedule - 05 Friday]]")
    case 6:
    case 0: return tp.file.include("[[Schedule - Weekend]]")
    default: return tp.file.include("[[Schedule - +Weekday]]")
  }
}

module.exports = scheduleTemplate

command.js

function command(action) {
  const allCommands = app.commands.listCommands();
  const command = allCommands.filter(
    (command) => command.name.toUpperCase() === action.toUpperCase().trim()
  )[0];
  app.commands.executeCommandById(command.id);
  return '';
};
module.exports = command;

Daily note Template

<% tp.user.scheduleTemplate(tp) %>
<%* if(moment(tp.file.title).isSame(new Date(), "day")) tp.user.command("Day Planner: Link today's Day Planner to the current note") %>

Explanation

Discussion

Link: https://github.com/SilentVoid13/Templater/discussions/240#discussioncomment-829917

I'll jump in, since I was planning on writing a how-to anyhow (so future-me doesn't forget how I set this all upย ๐Ÿ˜†)

For example, here's my Daily Notes template (I'm also using the Tasks plugin, which is what all the fol-de-rol at the bottom is about):

# Daily Log -- {{ date:MMM D, YYYY}}

<% tp.date.now("YYYY", 0, tp.file.title) %> ยป  <% tp.date.now("MMMM", 0, tp.file.title) %>  ยป  Week <% tp.date.now("ww", 0, tp.file.title) %>
 โ‡ฆ Previous Day |  Next Day โ‡จ 

<% tp.user.daily_schedule(tp) %>
<%* if(moment(tp.file.title).isSame(new Date(), "day")) tp.user.command("Day Planner: Link today's Day Planner to the current note") %>
---

## Tasks
### Overdue 
- Personal
	```tasks
	not done
	path includes Task List
	due before {{ date:YYYY-MM-DD }}

Due today

Due w/in 7 days

No due date

Done today


Notes


You can see that under the breadcrumb, I'm usingย [@deathau](https://github.com/deathau)'s script to load my daily schedule. Here's an example of my Friday schedule:


Day Planner


The super awesome thing aboutย [@deathau](https://github.com/deathau)'s script is that if you create your daily note on that day, it automatically links it to the Day Planner plugin, which is way spiffy!ย ๐Ÿ˜€

Alternative

Slight tweak of the function but allows customization of notes within obsidian. This way you can modify the included files within obsidian including using [[]] to autocomplete

function scheduleWeekday(tp, files) {
  switch (parseInt(moment(tp.file.title).format('d'))) {

    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
      return tp.file.include(files.weekday)

    case 0:
    case 6: return tp.file.include(files.weekend)
  }

}
module.exports = scheduleWeekday;

Invocation:

<% 
    tp.user.scheduleDaily(tp, {
          weekday:  "[[Utilities/Templater/Templates/Blocks/Process/P-Weekdays]]",
          weekend:      "[[P-Weekends]]",
    }) 
%>

up:: ๐Ÿงช Code Diary