# Sorting: How to use Liquid's filter instead of Jekyll's?

**URL:** <https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160>\
**Category:** Help\
**Created:** [November 10, 2017, 6:53pm UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160 "2017-11-10T18:53:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![floyd](https://avatars.discourse-cdn.com/v4/letter/f/439d5e/32.png) [@floyd](https://talk.jekyllrb.com/u/floyd)\
**Post date:** [November 10, 2017, 6:53pm UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/1 "2017-11-10T18:53:16Z")

</div>

Hello,

I want to sort the content of a custom data file (YAML), located in `_data` directory, before  
using it in a GitHub page. Since Jekyll’s `sort` filter raises an error/exception instead of just  
warn and gracefully ignore/pass-through items which cannot be sorted (like nil, different  
data types or hash against hash), it is useless, because I want to handle (drop, modify,  
replace, etc.) those datas in page source itself – think of a try/catch block.

As far as I understand, the [Liquid `sort` filter](https://github.com/Shopify/liquid/blob/27c9120/lib/liquid/standardfilters.rb#L118) seems not to raise an exception and therefore  
I would give it a try but don’t know how to syntactically specify this filter.

**Background** :

The custom data file may be edited by users not very familar with Jekyll/Liquid/YAML etc.  
So, when there is a “mistake” (items the `sort` filter cannot handle), the exception raised:

- points to the HTML and not to the YAML source file
- offers a very imprecise number of error line (just a guess, due to not take  
file front matter and/or comment lines into account)

This may be too confusing to contributors and they probably give up because life is too short.

Thanks for any input but hacks like wrapping potential failing data into strings by using  
`group_by_exp` filter or things that increase complexity or pollute source is not an option.

I want a `sort` filter that doesn’t touch and pass-through data it cannot handle without  
raising unnecessary exceptions. Something like `{{ data | join: ', ' }}` which just  
simply works for boolean, number, string types _and_ arrays (of mixed data types).

Regards

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [November 11, 2017, 6:55pm UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/2 "2017-11-11T18:55:10Z")

</div>

I must admit that I haven’t understood your problem, but got curious and found [this](https://jekyllrb.com/docs/templates/)…:

> Jekyll uses the Liquid templating language to process templates. All of the standard Liquid tags and filters are supported.

;/

---

<div class="post-metadata">

**Author:** ![floyd](https://avatars.discourse-cdn.com/v4/letter/f/439d5e/32.png) [@floyd](https://talk.jekyllrb.com/u/floyd)\
**Post date:** [November 11, 2017, 10:06pm UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/3 "2017-11-11T22:06:04Z")

</div>

My point is that both, _Jekyll_ and _Liquid_, have their own ideas how to implement sorting.  
Thus, two different implementation exists, the [Jekyll `sort` filter](https://github.com/jekyll/jekyll/blob/6ce912e/lib/jekyll/filters.rb#L260) and the [Liquid `sort` filter](https://github.com/Shopify/liquid/blob/27c9120/lib/liquid/standardfilters.rb#L118).

Now my origin point: How to select the latter `sort` filter when the former has the same  
name (probably in the same namespace)?

To hopefully be more specific on my second point, I cannot believe a filter stops the whole  
page build (like Jekyll’s sort implementation) when it cannot handle a (proper) data type.

`<rhetorical>`How many websites would lose their audience if a browser stops the page  
rendering when it founds an unknown/unsupported CSS property?`</rhetorical>`

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [November 11, 2017, 11:40pm UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/4 "2017-11-11T23:40:25Z")

</div>

Thanks for your explanation, @floyd!  
I hope some else will show up with and answer to your question. Meanwhile, I’ll keep reading through this issue: [https://github.com/jekyll/jekyll/issues/5808](https://github.com/jekyll/jekyll/issues/5808) (:

---

<div class="post-metadata">

**Author:** ![floyd](https://avatars.discourse-cdn.com/v4/letter/f/439d5e/32.png) [@floyd](https://talk.jekyllrb.com/u/floyd)\
**Post date:** [November 13, 2017, 10:38pm UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/5 "2017-11-13T22:38:09Z")

</div>

> [@lsrdg](#):
>
> I hope some else will show up with and answer to your question.

I fear that doesn’t gonna happen because I realised I’ve expected too much from  
a simple template language like Liquid. We can be thankful for control flow  
structures and variables.

Differentiate between data types is beyond the feature of a language that  
mostly just delegate its functionality to an underlying system (which does the  
real work).

My fault was to use YAML which provides some kind of data types (null, boolean,  
string, sequence, map, etc.). I better have to use CSV as custom data file  
because all is just a string (which probably can be interpreted as a date, number  
or whatelse).

Thank you @lsrdg for your response and links.

Cheers

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [November 14, 2017, 8:43am UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/6 "2017-11-14T08:43:40Z")

</div>

Wow. I actually learned a lot here. Thanks, @floyd .

Are you sure it is not worth an issue on github? Most likely you were not the first to face this kind of problem. If it was not on GH-pages, you could probably run a script to process that data before building. However, I must admit that I was expecting that something like `capture` and/or `assign` would be able with that…

Thanks for your question and explanations. Again, learned a lot. 👍

---

<div class="post-metadata">

**Author:** ![pathawks](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/pathawks/32/1317_2.png) [@pathawks](https://talk.jekyllrb.com/u/pathawks)\
**Post date:** [November 16, 2017, 3:50am UTC](https://talk.jekyllrb.com/t/sorting-how-to-use-liquids-filter-instead-of-jekylls/1160/7 "2017-11-16T03:50:01Z")

</div>

Sorry **floyd** , but it is not possible to use Liquid’s `sort` filters instead of Jekyll’s out of the box.

What you _could_ do is create a plugin to override Jekyll’s `sort` filters with Liquid’s.
