Entry fields when inserting a template or creating new files from template

I’m looking for something like VScode’s snippet fields where, when a template is inserted into a note or when a new note is created from a template, I’m left with input fields in the content where I can tab through the fields and add text to each. Is there such a thing?

I’m currently using templater system.prompt() but it becomes a bit messy when the number of inputs starts rising.

What I’m trying to do

Things I have tried

You could potentially try out tp.file.cursor() with or without numbers. That allows for cursor placement within your template, and it has commands (which can be connected to hotkeys) to navigate to the next cursor. See tp.file - Templater

It’s even allowed to define the same cursor multiple places, and insert the same text to all of those places at the same time. I use that in some button definitions where I need to insert a line number into 6 different locations, so using this I enter the number just once.

Note that it might be needed to enable the Settings > Templater > Automatic jump to cursor for this to work nicely.

That could work but I’m having trouble placing more than one tp.file.cursor. The first always works but the second and subsequent show the code and aren’t working. What am I missing?

Show us what you tried?

It should look something like this:

Field a:: <% tp.file.cursor(1) %>
Field b:: <% tp.file.cursor(2) %>

More text, or fields or whatever...

Field n:: <% tp.file.cursor(n) %>

It’s not working for me. With your code - n replaced with 3 - I get as the below screen grab when I insert the template. I can tab throough the cursor positions but I can’t enter text.

OK, I think I have it. When the template is first inserted the text input marquee isn’t in the note and I have to tab to get it there. Once I have the marquee in the note I can use to tab between the cursor positions. It works but it’s easy to break it.

I made a short screenflow which may make things clearer: https://www.dropbox.com/s/c15up5k6ufgxz10/ScreenFlow.mp4?dl=0

Alternatively, hit the escape key after the template is inserted will place the text input marquee into the note at the first cursor position

This sounds like you don’t have enabled the Settings > Templater > Auto jump to cursor setting, which should bring your cursor to the first instance. Can you verify that is enabled?

Yeah, Automatic jump to cursor is enabled.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.