Download

{{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.

What are you waiting for?

Start building your site today.

  1. 1 Download Publii
  2. 2 Write your content
  3. 3 Publish your site
Create website