Insert template and get a promt to edit part of the text with multiple choice

What I’m trying to do

Using the Badges plugin you can create badges using
`[!!!KEY:content]`
The KEY has multiple variables like note, tldr, warning, etc.

I want to create a template which inserts the above text, and gives me list to choose one key, and ends with my cursor ready to edit the text

The ideal, but unrealistic example would be the prompt to insert admonitions from Admonitions plugin
Screenshot (5)

Things I have tried

  • The only thing I succeded is
    `[!!key:<% tp.file.cursor() %>]`
    Can insert the template and leaves the cursor correctly.

  • I found that using
    <%*
    key = tp.system.suggester((key) => key, [“note”, “tldr”, “example”, “info”])
    %>
    gives me a list, but I don’t know how get it to do what I want.


    As I understand, I have to set the KEY as a variable and have the prompt let me edit it.

  • This does nothing (want to tackle one thing at a time)
    <%*
    `[!!key:content]`
    key = tp.system.suggester((key) => key, [“note”, “tldr”, “example”, “info”])
    %>`

Try the following:

<%*
const key = tp.system.suggester((key) => key, ["note", "tldr", "example", "info"])
tR += "[!!key:" + key + "]"
_%>

Now we store the result into key, and output it using the predefined tR variable.

2 Likes

Thank you!

Had to edit some stuff to get it to work, but your answer pointed me in the right direction.
Had to add ‘await’ infront of the system command, and change some of the other stuff related to Badges syntax.

<%*
const key = await tp.system.suggester((key) => key, ["note", "tldr", "example", "info"])
tR += "`[!!" + key + ":content]`"
_%>

So the final version,

<%*
const key = await tp.system.suggester((key) => key, ["note", "tldr", "example", "info"])
tR += "`[!!" + key + ":" + tp.file.cursor() + "]`"
_%>
2 Likes

I’m on mobile so I copy-pasted parts without thinking, but you do need the await for sure. And I misunderstood the badge syntax a little. :slight_smile:

But good for you that you got it working!

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