Templater Scripting Questions

Here is the code I’m working with

[call-date:: <% tp.system.prompt("Date", tp.date.now("YYYY-MM-DD")) %>] - <% tp.system.suggester(["Main", "Backup", "Main GV", "Backup GV"], ["[called:: (602)295-1875]", "[called:: (602) 295-7930]", "[called:: <U+202A>(602) 903-4748<U+202C>]","[called:: (xxx) xxx-xxxx]"]) %> ] - [call-time:: <% tp.system.prompt("Time", "") %>] - [callerID:: <% callerID = await tp.system.prompt("Caller ID", "")%>]  [[<% callerID %>]] - <% tp.system.suggester(["Inbound", "Outbound"], ["[call-direction:: Inbound]","[call-direction:: Outbound]"]) %>  - <% atds = await tp.system.suggester(["ATDS True", "ATDS FALSE"], ["[ATDS:: TRUE]", "[ATDS:: FALSE]"])%> - <% tp.system.suggester(["Call", "Voicemail", "Text Message"], ["[call-type:: Call]", "[call-type:: Voice Mail]", "[call-type:: Text]"]) %>  - <% tp.system.suggester(["Human", "Pre-Recorded/Automated"], ["[pre-recorded:: FALSE]", "[pre-recorded:: TRUE]"]) %> - notes -  <% tp.system.suggester(["Life Insurance", "Medicare", "Health Insurance", "Solar", "Legal-Auto", "Legal-Camp Legune","Vacation", "Other"], ["[campaign:: Life Insurance]", "[campaign:: Medicare]", "[campaign:: Health Insurance]", "[campaign:: Solar]", "[campaign:: Legal-Auto]", "[campaign:: Legal-Camp Legune]","[campaign:: Vacation]","[campaign:: Other]"]) %>  [compensatable:: TRUE]

Question 1:
When I run the script, some of the prompts come up in different windows, some of them com up in the same window sequentially, and they pop up in different places on the screen, and not in the order I would expect.

Can you see any reason why that happens? Is there anyway to control the order in which they appear?

Question 2:
Does templater support if statements? it would be nice to have different selections based on previous selections.

Q2: See Obsidian: Building the Meta-Templater from Scratch - YouTube.

Question 1:
The order issue is easily solved by making sure you await each tp.system.prompt and tp.system.suggester. If they aren’t awaited they will pop up overlapping each other.

As for the location, that’s simply a function of Templater itself. Prompts are in the middle of the screen while Suggesters are at the top.

Question 2:
Yes, Templater does support if statement within Execution Command braces.

If you are doing that, I would recommend factoring out all the suggesters into a block at the top, then adding the results back into the format you want at the bottom.

Here’s an example with the fixes from Q1, feel free to modify and expand it to your needs:

let date = await tp.system.prompt("Date", tp.date.now("YYYY-MM-DD"));
let main_backup = await tp.system.suggester(["Main", "Backup", "Main GV", "Backup GV"], ["(602)295-1875", "(602) 295-7930", "<U+202A>(602) 903-4748<U+202C>","(xxx) xxx-xxxx"]);
let callTime = await tp.system.prompt("Time", "");
let callerID = await tp.system.prompt("Caller ID", "");
let callDirection = await tp.system.suggester(["Inbound", "Outbound"], ["Inbound", "Outbound"]);
let atds = await tp.system.suggester(["ATDS True", "ATDS FALSE"], ["TRUE", "FALSE"]);
let callType = await tp.system.suggester(["Call", "Voicemail", "Text Message"], ["Call", "Voice Mail", "Text"]);
let preRecorded = await tp.system.suggester(["Human", "Pre-Recorded/Automated"], ["FALSE", "TRUE"]);

// The ((item) => item) pattern works to use the same list twice
let campaign = await tp.system.suggester(((item) => item), ["Life Insurance", "Medicare", "Health Insurance", "Solar", "Legal-Auto", "Legal-Camp Legune", "Vacation", "Other"], false, "Campaign");

// You can do an if statement on any of the results, then change future results based on that
let variable_list;
if (callType === "Call") {
  variable_list = ["1", "2", "3"];
else {
  variable_list = ["a", "b", "c"];

await tp.system.suggester(variable_list, variable_list, false, "This list can change depending on the call type");

// The underscore will remove all the whitespace so the template is still on one single line
// https://silentvoid13.github.io/Templater/commands/whitespace-control.html

[call-date:: <% date %>] - [called:: <% main_backup %>] - [call-time:: <% callTime %>] - [callerID:: <% callerID %>]  [[<% callerID %>]] - [call-direction:: <% callDirection %>]  - [ATDS:: <% atds %>] - [call-type:: <% callType %>]  - [pre-recorded:: <% preRecorded %>] - notes -  [campaign:: <% campaign %>] - [compensatable:: TRUE]

You can also use inline ifs in a normal expression. Here’s an excerpt from one of my templates. (I included the execution command block just so the other expression makes sense, and because I wanted to be sure I was giving you code that’s been tested rather than making it up off the top of my head.)

const WEEKDAY = tp.date.now("dddd", 0, tp.file.title, "YYYY-MM-DD");
const __exists = await tp.file.exists(`library/templates/daily/${WEEKDAY}.md`); %># <% WEEKDAY %>

<% tp.file.include(`[[library/templates/daily/${__exists ? WEEKDAY : "default"}#Schedule]]`) %>

This part is an inline if statement that resolves to the value of WEEKDAY if there is a template for the current weekday, otherwise it resolves to the string default:

__exists ? WEEKDAY : "default"
1 Like

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