Escaping handlebars in template

Is there a way to escape handlebars in page templates in a way that will unescape them once the template is applied?

I have this code as a part of my weekly note template. The weeklyJournalSummary is my custom space script function.

```template
\{\{weeklyJournalSummary("{{weekStart}}")\}\}
````

I would like the the page generated from this template to look like

```template
{{weeklyJournalSummary("2025-01-20")}}
````

But the backslashes stay in the template resulting in

```template
\{\{weeklyJournalSummary("2025-01-20")\}\}
````

This means I have to manually remove the backslashes after creating a new weekly note.

Does anybody have an idea how to unescape the handlebars?

I looked at and around the template language docs but haven’t found the answer Template Language

PS: The reason I’m passing in the week start is that the live templating apparently doesn’t support the editor page name syscalls so I can’t ask for the page name of the weekly note.

I tired that snippet you shared and on my side it rendered like this:
image

Seems to be working, is this what you were expecting/looking for?

Thanks for the response @Hckr1123 :pray:

In my use-case, I don’t want the function to render, I want it to execute.

In other words:

If I use the following page template as a command:

---
description: "Open your weekly note page"
tags: template
hooks.newPage:
  suggestedName: "tmp/{{weekStart}}"
  confirmName: true
  openIfExists: true
  command: "Test Weekly Note"
---
## Daily notes

```template
\{\{weeklyJournalSummary("{{weekStart}}")\}\}
```

I get the following page:

## Daily notes

```template
\{\{weeklyJournalSummary("2025-01-20")\}\}
```

Notice how the backslashes have been preserved in the output.

The template renders as a simple string:

Whilst I need the page to be

## Daily notes

```template
{{weeklyJournalSummary("2025-01-20")}}
```

(notice the missing backslashes)

So that it renders using the space script function

Just to know whether I understand you correctly, are you trying to place a template inside a page template so that the inner template gets rendered on all new pages created using the page template?

If you place {{weeklyJournalSummary("2025-01-20")}} directly in the page template, without the ```template enclosure, that should render the weeklyJournalSummary() function on all pages created using this page template. Is that what you are trying to achieve?

You need to use escapeDirective for this.

More details here.

@bent0n This is it! thank you :pray:

@Hckr1123 Also thank you very much for your help :bowing_man:

@bent0n darn, I take it back. escapeDirective doesn’t solve the problem AFAICT since I still face the issue with nested handlebars.

The issue is that I need the inner handlebars to be evaluated at the time when I turn the page template into a page.

In other words,escapeDirective(weeklyJournalSummary("{{weekStart}}")) doesn’t work and I need the weekStart to turn into 2025-01-20 when the template becomes a page, otherwise the weekStart will be dynamic and after a week I see different results in my old weekly note.

I’m starting to thing that I’m approaching this from a wrong angle and I probably don’t know enough about the template language and the syscalls to find a more elegant solution.

EDIT: I can’t render the whole weeklyJournalSummary when turn the template into a page because I create the weekly page on Monday, but I want the query to be dynamically updated for the whole week.

You could make the weekstart remain dynamic but have the output dependent on the filename to solve your issue? It seems you name the file with the date your interested in…

edit: Or even easier, use the filename as input to your weeklySummary function

@bent0n That was the first thing I wanted to do, but think that live templates don’t support the syscall

PS: The reason I’m passing in the week start is that the live templating apparently doesn’t support the editor page name syscalls so I can’t ask for the page name of the weekly note.

I tried it again and when I use

const date = await editor.getCurrentPage();

in my spacescript function

Error rendering template Error: Unregistered syscall editor.getCurrentPage
    at data:application/javascript;base64,dmFyIERlPU9iamVjdC5k......dHtyaSBhcyBwbHVnfTsK:1:958
    at data:application/javascript;base64,dmFyIERlPU9iamVjdC5k......dHtyaSBhcyBwbHVnfTsK:1:1006
    at innerInvokeEventListeners (ext:deno_web/02_event.js:757:7)
    at invokeEventListeners (ext:deno_web/02_event.js:804:5)
    at dispatch (ext:deno_web/02_event.js:661:9)
    at dispatchEvent (ext:deno_web/02_event.js:1041:12)
    at pollForMessages (ext:runtime_main/js/99_main.js:218:7)
    at eventLoopTick (ext:core/01_core.js:175:7)

EDIT: This is the doc for the syscall editor.getCurrentPage from syscalls - @silverbulletmd/silverbullet - JSR

Try it in sync mode. I use the same syscall in my workflow and it works only in sync mode.