Giter Club home page Giter Club logo

Comments (11)

webercoder avatar webercoder commented on August 15, 2024 3

@mattdwen @MayhemChaos I know it's been a while, but I suppose for people in the future who have arrived here like me...

Handlebars helpers can take extra arguments (specified by name) after the default ones are provided. For more info on that, search for options.hash on this page: http://handlebarsjs.com/expressions.html

The withSort helper that the assemble.io guys wrote does this as well. If you provide dir="desc" after your arguments, the loop's array will be reversed and you'll be good to go!

{{#withSort pages "data.created" dir="desc" }}
  {{#unless data.exclude}}
    <li><a href="{{data.url}}">{{data.title}}</a></li>
  {{/unless}}
{{/withSort}}

Here is the code that does it:
https://github.com/assemble/handlebars-helpers/blob/master/lib/helpers/helpers-collections.js#L279

from assemble.io.

pacav69 avatar pacav69 commented on August 15, 2024 1

Refer to my 'Tip: Using the #withSort option for creating navigation menu

helpers/handlebars-helpers#200

from assemble.io.

doowb avatar doowb commented on August 15, 2024

Try putting quotes around the field...

<ul>
    {{#withSort pages "data.date"}}
        <li>{{data.title}}</li>
    {{/withSort}}
</ul>

If this works, the docs should be updated.

from assemble.io.

toby1kenobi avatar toby1kenobi commented on August 15, 2024

That seems to work, thanks for that, much appreciated!

from assemble.io.

jonschlinkert avatar jonschlinkert commented on August 15, 2024

created a new issue to update docs, since this is resolve I'll go ahead and close it

from assemble.io.

dvera123 avatar dvera123 commented on August 15, 2024

This works fine, but just sort by string, if you compare [1,2,10] output will be 1, 10, 2,

If you need to make an index, try something like a-001, a-002.

from assemble.io.

jonschlinkert avatar jonschlinkert commented on August 15, 2024

@dvera123 thanks, good to know.

from assemble.io.

mattdwen avatar mattdwen commented on August 15, 2024

Is there any way to do a desc sort on pages, without having to explicitly declare the collection in the Gruntfile?

E.g. It would be great if you could declare {{#withSort pages "data.date" desc}}

from assemble.io.

jonschlinkert avatar jonschlinkert commented on August 15, 2024

closing, we can continue discussion on handlebars-helpers repo

from assemble.io.

 avatar commented on August 15, 2024

I tried these options to no avail..

{{#withSort pages "data.sortOrder"}}
                {{#is data.section "main"}}
                    <li{{#is ../../page.dest this.dest}} class="active"{{/is}}>
                                      <a href="{{relative ../../page.dest this.dest}}">{{data.menutitle}}</a>
                                  </li>
                {{/is}}
            {{/withSort}}
layout: home.hbs
title: What is ZMIX?
section: main
sortOrder: a-000
---

Help?

from assemble.io.

satuweb avatar satuweb commented on August 15, 2024

@webercoder Great!

from assemble.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.