Page Template with "Navbar" to previous and next days, relevant to page's name

I have registered 3 functions in a space-script which strip the date out of my page folder structure that follows “*work/journal/%date%”, supplies a cleaned date to pass to dateAdd, then provides the date preceding and following that cleaned date.

These work as intended across my space, and I have a template generating correct frontmatter values from those functions’ output.

---
tags: template
description: Daily Work Notes
hooks.newPage:
  suggestedName: "*workdev/journal/{{today}}"
  confirmName: true
  openIfExists: true
  forPrefix: "*workdev/journal/"
  tags: #workjournaldev
  command: "New Work Note Dev"
  key: "Alt-Shift-i"
frontmatter: 
  pn: "{{CleanPN(@page.name)}}"
  pp: "{{CleanPNPre(@page.name)}}"
  px: "{{CleanPNNxt(@page.name)}}"
---
# Notes
|^|
___
# To-Do
- [ ]  📅{{tomorrow}}

The problem starts when I try to further build out the template page so it would create links to the previous and next day’s page.

---
tags: template
description: Daily Work Notes
hooks.newPage:
  suggestedName: "*workdev/journal/{{today}}"
  confirmName: true
  openIfExists: true
  forPrefix: "*workdev/journal/"
  tags: #workjournaldev
  command: "New Work Note Dev"
  key: "Alt-Shift-i"
frontmatter: 
  pn: "{{CleanPN(@page.name)}}"
  pp: "{{CleanPNPre(@page.name)}}"
  px: "{{CleanPNNxt(@page.name)}}"
---
```template
[[*workdev/journal/{{@page.pp}}|<<<]] [[*workdev/journal/{{@page.pn}}]] [[*workdev/journal/{{@page.pn}}|>>>]]

When I do this, I get the new page, but the links point to:

[[*workdev/journal/undefined|<<<]] [[*workdev/journal/undefined]] [[*workdev/journal/undefined|>>>]]

I’m guessing the template part of the template doesn’t have those frontmatter values generated when it creates that new page.

If anyone is interested in the space-script, that code is here:

~~~space-script
// Registering the dateAdd function to add days to a date
silverbullet.registerFunction({ name: "dateAdd" }, (baseDate, daysToAdd) => {
  // Use today's date if baseDate is null or undefined
  if (!baseDate) {
    const today = Temporal.Now.plainDateISO();
    baseDate = today.toString();
  }
  
  try {
    const parsedBaseDate = Temporal.PlainDate.from(baseDate);
    const resultDate = parsedBaseDate.add({ days: daysToAdd });
    return resultDate.toString();
  } catch (error) {
    console.error("Error in dateAdd function:", error);
    return null;
  }
});

// Registering the CleanPN function
silverbullet.registerFunction({ name: "CleanPN" }, (pagename) => {
  const removeQuotesAndPrefix = (pageName) => pageName.replace(/^"|\*workdev\/journal\/|\"$/g, '');
  let cleanedPageName = removeQuotesAndPrefix(pagename);
  console.log("Cleaned Page Name:", cleanedPageName);
  return cleanedPageName;
});

// Function to get cleanedPagePre (previous day)
silverbullet.registerFunction({ name: "CleanPNPre" }, (pagename) => {
  let cleanedPageName = silverbullet.functions.CleanPN(pagename); // Clean the page name
  let cleanedPagePre = silverbullet.functions.dateAdd(cleanedPageName, -1); // Subtract 1 day
  console.log("Previous Day:", cleanedPagePre); // Log previous day
  return cleanedPagePre.toString();
});

// Function to get cleanedPageNxt (next day)
silverbullet.registerFunction({ name: "CleanPNNxt" }, (pagename) => {
  let cleanedPageName = silverbullet.functions.CleanPN(pagename); // Clean the page name
  let cleanedPageNxt = silverbullet.functions.dateAdd(cleanedPageName, 1); // Add 1 day
  console.log("Next Day:", cleanedPageNxt); // Log next day
  return cleanedPageNxt.toString();
});
~~~

You need to use escapeDirective otherwise, it will be rendered on page creation. You want it to be rendered when you consult the page.

I think this should work:

```template
[[*workdev/journal/{{escapeDirective("@page.pp")}}|<<<]] 
```

Which after the template is instantiated will turn into:

```template
[[*workdev/journal/{{@page.pp}}|<<<]] 
```
1 Like

Thank you! Cleaned some things up and have this working, creating a neat-ish nav bar across the top of my work journal pages.

[[*work/journal/{{escapeDirective("CleanPagePre(@page.name)")}}|<<<]] [[*work/journal/{{escapeDirective("CleanPage(@page.name)")}}]] [[*work/journal/{{escapeDirective("CleanPageNxt(@page.name)")}}|>>>]]

Wasn’t aware of that function being a thing - on that note, is there a place I could go to reference a description of everything available as a Function?