Templater system.suggester - need help to sort resulting list :)

What I’m trying to do

I have a templater template which uses (among other things) a couple of lines pulling a list of files from the vault as a selection (which the user then selects etc.)

My problem is trying to sort the list which gets produced as the selection to choose from. I’ve tried using bits of code looked up on the 'net, but none work. So please help! I simply want an alphabetical list…

This is the code (I’ve put the two lines using suggester in bold):
const dv = this.app.plugins.plugins[“dataview”].api
let Project = (await tp.system.suggester((item) => item.basename, app.vault.getMarkdownFiles().filter(file => file.name.startsWith("1 ")), false, “Please select Project…”)).basename
let shortName = Project.slice(2)
let qcFileName = (await tp.system.prompt(“Note Title”))
let fileDate = (await tp.system.prompt(“Date”))
let fileTime = (await tp.system.prompt(“Time (HHmm)”))
let org = (await tp.system.suggester((item) => item.basename, app.vault.getMarkdownFiles().filter(p => dv.page(p.path).file.etags.includes(“#Org”)), false, “Please select Organisation…”)).basename
titleName = fileDate + " " + fileTime + " " + " - " + qcFileName
await tp.file.rename(titleName)
if (Project == “1 NONE”)
await tp.file.move(“/0400 Organisations/” + org + “/Notes/” + titleName)
await tp.file.move(“/0200 Projects/” + shortName + “/Notes/” + titleName)

Thanks in advance :grinning:

Hello did you ever get an answer with this?
How to sort templater dropdownlist data

Nope sadly, still struggling with an unordered list :pensive:

First, you should format your code like this for better readability:

// Code

Next, to solve your problem, replace

app.vault.getMarkdownFiles().filter(/* arbitrary code */)


app.vault.getMarkdownFiles().filter(/* arbitrary code */).sort(({ basename: left }, { basename: right }) => left > right ? 1 : left < right ? -1 : 0)
1 Like

Many thanks - works like a charm. And thanks for the formatting/readability tip too!

1 Like

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