Skip to content

Instantly share code, notes, and snippets.

@estrattonbailey
Created July 13, 2018 15:00
Show Gist options
  • Save estrattonbailey/934ba36fe0e67129afb9227c536537ea to your computer and use it in GitHub Desktop.
Save estrattonbailey/934ba36fe0e67129afb9227c536537ea to your computer and use it in GitHub Desktop.
Sort shopify collection by last names
<div class='collection-list no-pad rel'>
<div class='outer'>
<div class='container'>
{% assign lnames = '' %}
{% assign letters = '' %}
{% for collection in collections %}
{% if collection.title contains 'Designer:' %}
{% assign name = collection.title | split: ':' | last %}
{% assign rname = name | split: "" | reverse | join: "" %}
{% assign lrname = rname | split: " " | first %}
{% assign lname = lrname | split: "" | reverse | join: "" %}
{% if lnames == '' %}
{% assign lnames = lnames | append: lname | append: ':' | append: collection.handle %}
{% else %}
{% assign lnames = lnames | append: ',' | append: lname | append: ':' | append: collection.handle %}
{% endif %}
{% assign letter = lname | split: '' | first %}
{% if letters == '' %}
{% assign letters = letters | append: letter %}
{% else %}
{% assign letters = letters | append: ',' | append: letter %}
{% endif %}
{% endif %}
{% endfor %}
{% assign letters = letters | split: ',' | sort | uniq %}
{% assign alpha = lnames | split: ',' | sort %}
{% for letter in letters %}
<h2 id='{{ letter }}' class='mb05 mt1 medium'>{{letter}}</h2>
<div class='collection-list__cards f ais fw'>
{% for value in alpha %}
{% assign lname = value | split: ':' | first %}
{% assign firstletter = lname | split: '' | first %}
{% assign handle = value | split: ':' | last %}
{% if firstletter == letter %}
<div class='collection-list__card collection-list__card--designer'>
{% include 'collection-card' with collection: collections[handle] %}
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment