Templater: How to trigger tp.system.suggester() with tp.file.cursor()

What I’m trying to do

As we know, using tp.system.suggester() opens a dropdown like menu when the Template is initialized while tp.file.cursor() moves the cursor to whatever position it’s called.

I would like to trigger tp.system.suggester() exclusively when the next tp.file.cursor() is called. It’s worth saying that due to my flow using only tp.system.suggester() along with tp.system.prompt() on file creation isn’t an option.

Hypothetical Example for Simplicity

  1. On file creation I will get prompted for the color limited to **red **or blue.
  2. I have to fill in the description of the wings.
    • Some may suggest to use tp.system.prompt() but I can’t because it blocks the file contents that I must keep seeing while filling the file.
  3. Choose the size limited only to large or short.
Color: <% tp.system.suggester(["blue", "red"], ["blue", "red"]) %>
Wings: <% tp.file.cursor(1) %>
Size: <% tp.file.cursor(2); tp.system.suggester(["large", "short"], ["large", "short"]) /* This line will fail unless `tp.file.cursor(2);` is removed */ %>

Things I have tried

  1. Tried to place both instructions in the same line. (Same code as in the example)
    • <% tp.file.cursor(2); tp.system.suggester(["large", "short"], ["large", "short"]) %>
      • Error log: Templater Error: Template parsing error, aborting. Template syntax error: missing ) after argument list
      • I’m sure I didn’t miss a parenthesis.
  2. Googled for this or similar issues.
  3. Reviewed Templater’s source code but couldn’t figure this out. But at least now I know that tp.file.cursor() returns a string and not a Promise as I initally thought.

I’m not entirely certain, but I don’t think this particular workflow is achievable like you depicted it.

Using multiple template from buttons

Another way of achieving it could be through the use of multiple templates, and possibly using buttons instead of the tp.file.cursor() stuff.

The workflow would then be to do:

  • Insert the main template, presenting you with the file with the “Color”, “Wings” and “Size” fields, with buttons at their field value place.
  • Clicking on each button triggers a template, doing either the prompt or a suggester. Possibly you could skip the prompt for the “Wings” field, and just enter the value directly.

Using the meta-bind plugin

The Meta Bind plugin provides another alternative where it allows for fields to be selected in-file. Not sure if this would suit your workflow, but it’s worth considering, as it also allows for seeing the other information in the file when changing other input fields.

1 Like

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