Templater Help With Periodic Note Pagination Method Found On GitHub

What I’m trying to do

I’m trying to configure this pagination feature from a template I found on GitHub and it doesn’t seem to be working for me. After inserting it into a template, and then creating a note from that template, it all just disappears. Also using Replace template in the active file produces the same results.

Here is the code in the template/daily.md file:

<%* let today = moment(tp.file.title);

// # 2023/01/01 - Sunday tR += '# ' + today.format('YYYY/MM/DD - dddd') + '\n';

// 2023 / Q1 / January / Week 1 tR += '[[' + today.format('YYYY') + ']] / '; tR += '[[' + today.format('YYYY-[Q]Q') + '|' + today.format('[Q]Q') + ']] / '; tR += '[[' + today.format('YYYY-MM') + '|' + today.format('MMMM') + ']] / '; tR += '[[' + today.format('gggg-[W]ww') + '|' + today.format('[Week] w') + ']]'; tR += '\n\n';

// ❮ 2022-12-31 | 2023-01-01 | 2023-01-02 ❯ tR += '❮ [[' + today.subtract(1, 'days').format('YYYY-MM-DD') + ']]'; tR += ' | ' + today.add(1, 'days').format('YYYY-MM-DD') + ' | '; tR += '[[' + today.add(1, 'days').format('YYYY-MM-DD') + ']] ❯'; today.subtract(1, 'days'); %>

Things I have tried

I’ve tried playing around with the script, but I’m terrible with Javascript and getting nowhere. I ended up just using Templater to create a simple pagination for my daily and weekly notes, but I’d like to get something like this working.

I suspect it’s me just not formatting my dates right.

Here are my daily and weekly formats:

Daily:

YYYY/MMM/[W]-ww/dddd-MMM-DD-YY

Weekly:

YYYY/MMM/[W]-ww/YYYY-[W]-ww

There’s both in /Daily.

I also haven’t set up Monthly, Quarterly, or yearly note yet.

Most of the whole snippet you shared is actually commented out (99% of the lines start with // … which is how you add line comment in JS) :sweat_smile:
So, unless something happened when you copied/pasted it here, it could explain why it doesn’t work :innocent:

This seems to work though :blush: :

<%* 
// Get today's date from the daily note's title
// Daily note title format is "dddd-MMM-DD-YY"
const today = moment(tp.file.title, "dddd-MMM-DD-YY");
// Format today as "YYYY/MM/DD - dddd"
const heading = moment(today).format("YYYY/MM/DD - dddd");
// Format today as "YYYY" (for the link to the year)
const yearLink = moment(today).format("YYYY");
// Format today as "YYYY[-Q]Q[|Q]Q" (for the link to the quarter)
const quarterLink = moment(today).format("YYYY[-Q]Q[|Q]Q");
// Format today as "YYYY-MM[|]MMMM" (for the link to the month)
const monthLink = moment(today).format("YYYY-MM[|]MMMM");
// Format today as "gggg[-W-]ww[|Week ]w" (for the link to the week)
const weekLink = moment(today).format("gggg[-W-]ww[|Week ]w");
// Get "yesterday" and format it as "dddd-MMM-DD-YY[|]YYYY-MM-DD"
const yesterdayLink = moment(today).subtract(1, 'd').format("dddd-MMM-DD-YY[|]YYYY-MM-DD");
// Format today as "YYYY-MM-DD"
const todayNav = moment(today).format("YYYY-MM-DD");
// Get "tomorrow" and format it as "dddd-MMM-DD-YY[|]YYYY-MM-DD"
const tomorrowLink = moment(today).add(1, 'd').format("dddd-MMM-DD-YY[|]YYYY-MM-DD");
-%>
# <% heading %>

[[<% yearLink %>]] / [[<% quarterLink %>]] / [[<% monthLink %>]] / [[<% weekLink %>]]

❮ [[<% yesterdayLink %>]] | <% todayNav %> | [[<% tomorrowLink %>]] ❯ 

Note: the snippet, to work properly, needs to be applied to note titled following the format you chose for your daily note’s title … as the title is used in the snippet to determine when “today” is and format its date in various ways :blush:

So, the snippet applied to a note titled Saturday-October-26-24 output:

# 2024/10/26 - Saturday

[[2024]] / [[2024-Q4|Q4]] / [[2024-10|October]] / [[2024-W-43|Week 43]]

❮ [[Friday-Oct-25-24|2024-10-25]] | 2024-10-26 | [[Sunday-Oct-27-24|2024-10-27]] ❯ 

This can be adapted to your wishes/needs :blush:

I’m sadly a bit too short on time to give more explanations/informations :no_mouth: … but I hope it will still help a little :innocent:

1 Like

This is so awesome! Thank you so much for helping out. I’m going to modify it to work with my templates.

Cheers!

1 Like