Sort templates alphanumerically

Hello everyone! :person_raising_hand:

In short: Please make templates sorted alphanumerically

Long read:

I work a lot with checklists and have the problem that the (now quite long) list of my checklists is unsorted after entering /template :face_with_peeking_eye:

It would be easier to find what I’m looking for, if the List would be sorted alphanumerically.

I have already found this thread on the topic, but

  1. in my case the latest templates are not added at the end of the list (but somewhere randomly) and
  2. this workaround would be annoying if you want to add an entry on top or in the middle.

With alphanumeric sorting, one could organize the order of the templates via prefixes (01…99, or “private → Lorem Ipsum”, “professional → Lorem Ipsum”, etc.)

Kind regards

Till

1 Like

I have struggled with the same issue. I have even tried the solution that you mention but it simply doesn’t work (at least not in the latest 0.10.3 Win10/11 release).

@mentaloid helped me to arrange journal pages in ascending order on the desktop app’s default home page with some Javascript code (by default journal pages are listed by date in descending order). Could the same be done for the templates command palette?

custom.js:

document.addEventListener('keyup', (e)=>{    
    if (e.altKey && e.key === "s") {
        const divJournals = document.querySelector("#journals")
        if (!divJournals) return

        const journals = divJournals.querySelectorAll("div.journal-item")
        const arr = Array.prototype.map.call(journals, (j)=>j )
        arr.sort( (a, b)=>{
            const aname = a.querySelector(".journal-title h1").textContent
            const bname = b.querySelector(".journal-title h1").textContent
            return aname.localeCompare(bname)            
        })
        divJournals.querySelector("div").prepend(...arr)
    }
});
  • The mentioned code is from Logseq as a Journal app
  • The respective code for templates would be like this:
    document.addEventListener('keyup', (e)=>{    
        if (e.altKey && e.key === "t") {
            const divTemplates = document.querySelector('div[data-modal-name="template-search"]')
            if (!divTemplates) return
      
            const templates = divTemplates.querySelectorAll("div.menu-link-wrap")
            const arr = Array.prototype.map.call(templates, (t)=>t )
            arr.sort( (a, b)=>{
                const aname = a.querySelector("span.flex-1").textContent
                const bname = b.querySelector("span.flex-1").textContent
                return aname.localeCompare(bname)            
            })
            divTemplates.querySelector("#ui__ac-inner").prepend(...arr)
        }
    });
    
    • This works with Alt + t
      • That can be customized
    • However, it has side-effects to the list’s functionality.
      • Thoroughly test it before using in production.
1 Like

Thank you very much for your work!

Honestly, I don’t want to use the code in my current installation as I use it productively.

But since I haven’t gotten any other feedback on this yet, I’d rather change the category of this post to “feature request” and edit the initial post accordingly. This will also refer to your code and maybe your code will help the developers to implement a general solution for future versions.

1 Like

If you are using plugins: try 🏛 Full House Templates plugin.

It cannot sort in numeric order, but:

  1. It uses sorting by page and then by name by default (not in creation order)
  2. It provides fuzzy search of template names and it’s parent pages
  3. It provides a way to set a category for templates (via template-list-as:: property)
  4. I’ll add numeric search in the next release =)

Here is insertion template UI:

1 Like