From b86d45880a9c55fbf849ab6e662126007a9bb751 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 14 Nov 2023 09:51:36 +0100 Subject: [PATCH] Process handlebars in frontmatter for slash templates too --- plugs/template/api.ts | 3 +++ plugs/template/template.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugs/template/api.ts b/plugs/template/api.ts index 91582a1..179f9ae 100644 --- a/plugs/template/api.ts +++ b/plugs/template/api.ts @@ -31,6 +31,9 @@ export async function renderTemplate( } else { frontmatterText = await YAML.stringify(frontmatter.frontmatter); } + frontmatterText = await handlebars.renderTemplate(frontmatterText, data, { + page: pageMeta, + }); } return { frontmatter: frontmatterText, diff --git a/plugs/template/template.ts b/plugs/template/template.ts index 57fa037..b904490 100644 --- a/plugs/template/template.ts +++ b/plugs/template/template.ts @@ -35,7 +35,7 @@ export async function insertSlashTemplate(slashCompletion: SlashCompletion) { const templateText = await space.readPage(slashCompletion.templatePage); let { frontmatter, text } = await renderTemplate(templateText, pageObject); - const cursorPos = await editor.getCursor(); + let cursorPos = await editor.getCursor(); if (frontmatter) { frontmatter = frontmatter.trim(); @@ -49,6 +49,7 @@ export async function insertSlashTemplate(slashCompletion: SlashCompletion) { await editor.dispatch(dispatch); } + cursorPos = await editor.getCursor(); const carretPos = text.indexOf("|^|"); text = text.replace("|^|", ""); await editor.insertAtCursor(text);