GitHub

{{reverse}} helper

The {{reverse}} helper is useful if you need to reverse items in a specific collection e.g. tags listing.

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.

Subscribe

Get the latest Publii news, updates and more delivered directly to your email inbox

You can change your mind at any time by clicking the unsubscribe link in the footer of any email you receive from us, or by contacting us at contact@tidycustoms.net. By clicking below, you agree that we may process your information in accordance with our Privacy Policy.