URL param Sorting

Ascending Descending

  • Sort Order: ASC
  • Item 01
  • Item 02
  • Item 03
  • Item 04
  • Item 05
  • Item 06
  • Item 07
  • Item 08
  • Item 09
  • Item 10

Request Object

ie: {{request.request_url}}

{
  "href": "https://rtwebdocs.treepl.co/url-param-sorting?sort=asc",
  "origin": "https://rtwebdocs.treepl.co",
  "protocol": "https",
  "hostname": "rtwebdocs.treepl.co",
  "path": "/url-param-sorting",
  "params": {
  "sort": "asc"
},
  "originalparams": {
  "sort": [
    "asc"
  ]
}
}

Liquid code needed:

 
{% assign urlParam = request.request_url.params.sort %}
{% case urlParam %}
  {% when "asc" %}
     {% assign sortOrder = "ASC" %}
  {% when "desc" %}
     {% assign sortOrder = "DESC" %}
  {% else %}
     {% assign sortOrder = "ASC" %}
{% endcase %}

{% component source: "Count test", sortBy: "name", sortOrder: "{{sortOrder}}", collectionVariable: "sorting", type: "module" %}

<a href="/url-param-sorting?sort=asc">Ascending</a>
<a href="/url-param-sorting?sort=desc">Descending</a>

<ul>
{% for i in sorting.items %}
    <li>Item <b>{{i.name}}</b></li>
{% endfor %}
</ul>