Templater insert text at start or end of existing note regardless of current cursor position

The following template assumes you’re running it against an existing note.

<%*
const head = `---
aliases:
---

`;

const foot = `
your footer content here
`;

const tf = tp.file.find_tfile(tp.file.title);
await app.vault.modify(tf, head + tp.file.content + foot);
-%>

In my testing, the cursor ends up at the beginning of the note after adding the content. If you don’t want the cursor to move, well, that becomes a taller order which would require more thinking on my part.

2 Likes