If-Then construction within Templater Suggester function

Things I have tried

I’ve tried experimenting with my current code and searching on javascript sites, but I’m not a coder so unable to make too much progress. Of course, have scoured the obsidian forum…

What I’m trying to do

I’m trying to optimize my use of Suggester within Templater. Currently I use the following which allows me to choose the Fund I want to write about:
<% (await tp.system.suggester((item) => item.basename, app.vault.getMarkdownFiles().filter(file => file.path.startsWith(“020 Investments/Funds”)))).basename %>

However, I’d like to be able to utilize an If-Then construction. IF it’s a Fund, then choose one folder…IF a Business, then choose another folder. Put another way, I’d like my answer to an initial suggester (“Is it a fund or business”), determine which folder suggester points towards for the following variable.

It sounds like this should be doable, using a little javascript inside a <%* %> block.

The way I’d tackle it would be:

  • set the selected value of the initial (“Fund” | “Business”) suggester to a variable
  • check the value of that variable against your logic
    • use an if-then or a switch-case structure to send out the second suggester with the desired options (using your same logic as above), setting the selected file’s basename to a new variable
  • from there you can use the new variable to add the text into the note with the line ‘tR += whatever_you_named_your_variable’

Apologies for the poor formatting, I’m relatively new to using forums like this one.

I’m also still new to Obsidian and I’ve been feeling my way through everything, but I believe this should work. I hope that helps some!

Thanks very much - I’m going to continue to work may way through this challenge. Best of luck getting up to speed in Obsidian - it’s great !

1 Like