Nesting the tp.system.suggester with in the tp.system.prompt

I got one of my questions here for an end-user response when the answer to the question is not on the list. I achieved this by using the folllowing snatched from this post

<%*
let choice = tp.system.suggester(['Yes','No','User Defined'],['Yes','No','User Defined']);
if (choice == 'User Defined')
{
   choice = tp.system.prompt('Other choice');
}
-%>

What I can not figure out for the life of me is how to have the question show up on the prompt for the answer. As it sits now I receive a suggester asking for the answer "‘Yes’,‘No’,‘User Defined’. What i would like to figure out is how to have the question show up so i know what question I am answering. What it comes down to is can not figure out the context for nesting the tp.system.suggester with in the tp.system.prompt.

Have you read the documentation?

https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html

It suggests using a placeholder for the question, which leads to something like:

<%*
const question = "What?"
let choice = tp.system.suggester(['Yes','No','User Defined'],['Yes','No','User Defined'], false, question);
if (choice == 'User Defined')
{
   choice = tp.system.prompt(question);
}
-%>

Or some variation thereof.

your snippet helped a ton. Thank you. I had read that lined documentation but your example helped me understand it better. The issue is now when I use your snippet and answer the question of “What”, the answer does not appear at all just a blank note. Thank you for helping out a new guy. Very Thankful.

You still need to insert the answer somewhere. Either within that same block using tR += choice, or somewhere else in your file using <% choice %>.

this worked!

<%*
const question = "What?"
let choice = tp.system.suggester(['Yes','No','User Defined'],['Yes','No','User Defined'], false, question);
if (choice == 'User Defined')
{
   choice = tp.system.prompt(question);
}
-%>
`<% choice %>`. 

Thank you for your guidance!

1 Like

OK now to add to this question. How do I ask multiple questions in the same template? The snippet above works but as soon as I duplicate it and ask the second question “Where” I get the following error:

plugin:templater-obsidian:61 Templater Error: Template parsing error, aborting.
Template syntax error: Identifier ‘question’ has already been declared

I realize this might be a basic issue but very thankful for your assistance.

You change the const to let, and give it a new value similar to that when re-using the choice variable.

It could be well worth the time to do some basic javascript tutorials to learn this stuff.

I will admit I am new to this but trying to learn as I go and will be trying to dig into some javascript classes soon. This is what I have and am confused about your last response" and give it a new value similar to that when re-suing the choice variable,"

Venue:
<%*
let question = "Venue?"
let choice = tp.system.suggester(['home','office','User Defined'],['home','office','User Defined'], false, question);
if (choice == 'User Defined')
{
   choice = tp.system.prompt(question1);
}
-%>
`<% choice %>`.
Worked:
<%*
let question = "Worked?"
let choice = tp.system.suggester(['YES','NO','User Defined'],['YES','NO','User Defined'], false, question);
if (choice == 'User Defined')
{
   choice = tp.system.prompt(question);
}
-%>
`<% choice %>`.

any further assistance would be very appreciated!

No need for the let in the second block, they’re already declared and can just be used as is.

That worked, so if you declare it as “let” then that will allow for each expression with “question” to be unique for the entire block. Correct? Thank you for all your help!
for the future this is the code that worked:

<%*
let question = "Venue?"
let choice = tp.system.suggester(['home','office','User Defined'],['home','office','User Defined'], false, question);
if (choice == 'User Defined')
{
   choice = tp.system.prompt(question1);
}
-%>
`<% choice %>`.
Worked:
<%*
question = "Worked?"
choice = tp.system.suggester(['YES','NO','User Defined'],['YES','NO','User Defined'], false, question);
if (choice == 'User Defined')
{
   choice = tp.system.prompt(question);
}
-%>
`<% choice %>`.

It’ll be that value until you change it to something else.

1 Like

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