{{orderby}} helper

{{orderby}} is a helper similar to the {{reverse}} helper - it changes the ordering of the specific collection using your params. Additionally, it supports an extra parameter, langForLocaleCompare, enabling locale-sensitive sorting based on the specified language code.

Syntax:

{{orderby collection field direction [langForLocaleCompare]}}

Example:

{{#each @website.contentStructure.tags}}
   {{#checkIf this.name '===' 'test'}}
      {{orderby this.posts 'id' 'DESC' 'pl'}}      
      {{#each this.posts}}
         {{title}}
      {{/each}}
      {{orderby this.posts 'id' 'ASC' 'pl'}}
   {{/checkIf}}
{{/each}}

In the above example, we reverse posts connected with a specific tag using their ID and apply locale-sensitive sorting according to the Polish language ('pl'). This ensures that sorting considers language-specific rules, enhancing the accuracy and relevance of sorted data for multilingual websites.

Important! You should restore the original ordering after the use of the modified output. That's why we use the {{orderby}} helper two times, including after locale-specific sorting operations.

Create your first website with Publii

Join thousands of creators who chose independence. Create content locally and publish lightning-fast, secure websites on your own terms.

Download Publii

Free and open source. Windows, macOS and Linux.

Read the getting started guide