Feature Request: Order Article Attachments

8 Comments

  • Adam Ashby-Clarke

    Came here looking for this exact same thing.  Weirdly they are organised when I edit the article, by name, which is fine since we use version numbers, but on the article that is published they appear random...

    1
  • Holly

    We would like this as well!

    1
  • Kristina Tibbitts

    This would be extremely helpful!

    0
  • Yoshiko Matsuo

    I request the same feature

    0
  • Conny Svanberg

    Exactly what I am looking for right now...

    0
  • Christophe Tiraboschi
    Zendesk Customer Care

    Hi Everyone,

    As a workaround, here is a piece of Javascript to order attachements by alphabetical order on the front-end of an article:

    const reorder = () => {
    const frag = document.createDocumentFragment();
    const list = document.querySelector(".attachments");
    const items = list.querySelectorAll("li");
    const sortedList = [...items].sort((a, b) => {
    const c = a.textContent,
    d = b.textContent;
    return c < d ? -1 : c > d ? 1 : 0;
    });
    for (const item of sortedList) {
    frag.appendChild(item);
    }
    list.appendChild(frag);
    }

    reorder()

    You can use this code in the script.js file of your theme, ideally just before the last closing bracket.

    If you have a custom theme, please double check that the <ul> tag listing the attachements has still the class "attachements". You can find it in the article_page.hbs file at the line 96 in the default theme (see screenshot attached). If the name of the class was changed, you would need to adjust the third line of the snippet provided above by replacing "attachements" with the new class name.

    0
  • Conny Svanberg

    Thanks a lot, Christophe!

    Made my life a lot more easy to live... :-)

    0
  • Adam Ashby-Clarke

    Hi Christophe Tiraboschi,

    Thanks for this, I have tried adding this as it has been very frustrating not having it, however it has not changed the article, they are still ordered incorrectly.  Please advise what I can check?  Using the default Copenhagen theme.  This is the bottom of my script.js.

    And this is my article page where you will see they are still in a different order (ive blocked the first part of the filename, but it is identical), the only difference is the version number at the end, im wondering does your workaround apply to numbers also?

    0

Please sign in to leave a comment.

Powered by Zendesk