Templater - insert Template via suggestor

Hello,
I’m currently trying to implement a <% tp.file.include(‘[[Template]]’) %> into a suggestor. The suggestor should ask whether the template should be inserted or not.
I’ve used the following code, but unfortunately it’s not working:

<% await tp.system.suggester([“insert Template”, “nothing”], [“<% tp.file.include(‘[[Template]]’) %>”, “”], false, “What to do?”) %>

ANy ideas how to fix it?

Wouldn’t it be better to use a yes/no prompt, and then insert if it’s true?

Something along these lines:

<%* 
const insertTemplate = await tp.system.suggester(["Yes", "No"], ["true", "false"])
if ( insertTemplate ) 
  tR += tp.file.include('[[Template]]')
%>

same error as before: template parsing error, aborting.

Also tried it with other templates.

So I modified it a little, as I had some stupid mistakes in my first attempt, so this is the new and improved version:

<%* 
const insertTemplate = await tp.system.suggester(["Yes", "No"], [true, false])

if ( insertTemplate )
  tR += await tp.file.include('[[Template]]')
%>

Try that, and if still gives the same error, try this one:

<%* 
const insertTemplate = await tp.system.suggester(["Yes", "No"], [true, false])

if ( insertTemplate )
  tR += "Should be a template"
%>

And it should add that line of “Should be a template” into your file. If it still fails, then either are you copying stuff wrongly, or you have something else wrong in other Templater user functions or templates.

3 Likes

thank you a lot. i will try it when i am back home

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