[Templater] How do execute code when a tp.file.cursor is hit?

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

Using an execution command (<%* ... %>) as opposed to <% ... %>, this seems to work for me:

<%* tp.file.cursor(); console.log("now i'm here") %>

… but that might not solve your issue though :sweat_smile:

When it comes to Properties/Frontmatter, I prefer using tp.system.prompt or tp.system.suggester if I want/need to add/select specific values… maybe that could be an option :woman_shrugging:

@Pch, Thanks for the suggestion! I now see the "now i'm here" output, but the "tp.file.cursor(3)" is gone and I can no longer jump to the location :confused: