-
-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sort_by to sort posts/pages #1802
Comments
I think it'd be smarter to write the {% for group in site.pages | group_by: "category" | sort_by: "name" %}
<h2>{{ group.name }}</h2>
<ul>
{% for page in group.items %}
<li>{{ page.title }}</li>
{% endfor %}
</ul>
{% endfor %} |
How would you sort by category, then date, then author? |
It'd be great to be able to pick the property to sort on for a "complex object". An example, taken from the ossPerks.com front-matter, which sorts on a perk's name:
Another alternative (not as nice) would be to annotate the property to sort on in the YAML:
which would simplify the syntax used in the
|
I agree with @haacked that multi-level sorting is important, but I don't care much about the syntax to make it work. |
@haacked Does the Liquid
From: http://docs.shopify.com/themes/liquid-basics/output#manipulation |
Interesting. I don't see any way to specify 'ascending' or 'descending'. |
@haacked Right, because they also have the {{ my_array | sort | reverse }} |
Ahh! Ok, I'll close this. :) |
Note that you can only sort |
Oh snap! That is very limiting. I should be able to sort by any property of page including custom fields. So is this an issue for liquid then? |
I'll take a crack at it. |
Related to #1735
Proposed syntax:
If you don't specify 'asc' or 'desc' then it should probably do it 'desc' by default?
Also, I found a proposed
:order
keyword here: http://stackoverflow.com/questions/9218769/order-an-array-with-jekyll-liquid-templateSeems to me that chaining methods makes more sense to be consistent with the other operations, but I don't feel too strongly either way.
One thing to consider is multiple sorts:
site.pages.sort_by(:someProperty, 'asc').then_by(:anotherProperty, 'desc');
But I leave it to you to sort out the rubyisms. (pun intended).
The text was updated successfully, but these errors were encountered: