What I’m trying to do
I want to execute some js code when a
<% tp.file.cursor(3) %>
is hit.
Is there even any way to do that? The tp.file.cursor
function does not take any callback arguments.
Things I have tried
I tried writing something like
<% (tp.file.cursor(3), console.log("now i'm here")) %>
or
<% tp.file.cursor(3); console.log("now i'm here") %>
but I get erros like
Template syntax error: missing ) after argument list
And this does not do anything:
<% tp.file.cursor(3, () => console.log("now i'm here")) %>
Additional context
In case you want to know why I try doing this:
When I create a new note, the template automatically switches me into source mode, such that I can quickly jump to the ‘aliases’ then to the ‘tags’ section in the frontmatter:
---
id: <% id %>
title: <% title %>
aliases:
<% aliases.reduce((acc, x) => x ? `${acc} - ${x}\n` : acc, "") -%>
- <% tp.file.cursor(1) %>
tags:
<% tags.reduce((acc, x) => x ? `${acc} - ${x}\n` : acc, "") -%>
- <% tp.file.cursor(2) %>
creation_date: <% tp.date.now("yyyy-MM-DD HH:mm") %>
---
because if I don’t switch to source mode, the cursor jumps don’t work anymore because obsidian interprets - <% tp.file.cursor(1) %>
as a value.
Now I then have the press a hotkey when I get to my
# <% heading %>
<% tp.file.cursor(3) %>
below in order to get switch to editor mode, which has gotten annoying.
Maybe there even is another way of accomplishing what I want without templater.
Any help is welcome!
Thanks in advance <3