# Access filename of new file in templates and space scripts during creation

**URL:** https://community.silverbullet.md/t/access-filename-of-new-file-in-templates-and-space-scripts-during-creation/516
**Category:** General
**Created:** [June 16, 2024, 5:06pm UTC](https://community.silverbullet.md/t/access-filename-of-new-file-in-templates-and-space-scripts-during-creation/516 "2024-06-16T17:06:53Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Maarrk](https://community.silverbullet.md/user_avatar/community.silverbullet.md/maarrk/32/56_2.png) [@Maarrk](https://community.silverbullet.md/u/Maarrk)
#### Post date: [June 18, 2024, 5:27pm UTC](https://community.silverbullet.md/t/access-filename-of-new-file-in-templates-and-space-scripts-during-creation/516/2 "2024-06-18T17:27:30Z")

</div>

Hi, I think I had exactly the same problem when trying to add previous/next links to my daily journal.

I tried to access this filename in a few ways and didn’t succeed. But I used a template to evaluate it only when the file is shown, and then if I don’t want it to be templated anymore (for example to get red links), I use the bake button in the corner.

The `escapeDirective` call is needed to evaluate it when shown, not when created.

* * *

This is at the top of my `Library/Journal/New Page/Daily Note` (the links are Polish for “yesterday tomorrow”)

````auto
```template
[[{{escapeDirective('pageAddDays(@page.name, -1)')}}|wczoraj]] [[{{escapeDirective('pageAddDays(@page.name, 1)')}}|jutro]]
```

````

![screenshot with bake button](https://community.silverbullet.md/uploads/default/original/1X/27d626a859337b518307a684f43dab865805355c.png)

> **Definition of pageAddDays for completion**
>
> ````auto
> ```space-script
> silverbullet.registerFunction("pageAddDays:", (page, days) => {
> const parts = page.split("/");
> let date = parts[parts.length - 1];
> const plainDate = Temporal.PlainDate.from(date);
> const offsetDate = plainDate.add(Temporal.Duration.from({ days: Number(days) }));
> const result = parts.slice(0, -1);
> result.push(offsetDate.toString());
> return result.join("/");
> });
> ```
> 
> ````

Sorry I didn’t adapt it, I only have a moment to paste my current code. I hope that it still shows the approach to help with your solution 🙂

---

_[View the full topic](https://community.silverbullet.md/t/access-filename-of-new-file-in-templates-and-space-scripts-during-creation/516)._
