{{reverse}} helper

The {{reverse}} helper is useful if you need to reverse items in a specific collection e.g. tags listing. To sort by a specific field, use orderby.

Syntax:

{{reverse collection}}

Example:

{{#each @website.contentStructure.tags}}
   {{#checkIf this.name '==' 'test'}}
      {{#if this.postsNumber}}
         {{reverse this.posts}}
         {{#each this.posts}} {{! this output is reversed }}
            {{title}}
         {{/each}}           
         {{reverse this.posts}}
      {{else}}
         There are no posts connected with tag name "test"
      {{/if}}
   {{/checkIf}}
{{/each}}

Important! You should restore original ordering after use of the modified output. That's why our example contains double call of the {{reverse}} helper - the first call reverse the order of elements and after getting a reversed output we reverse the collection again to get original ordering.

 

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