# How do you do case-insensitive list sorting

**URL:** <https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548>\
**Category:** support\
**Created:** [January 23, 2019, 1:26am UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548 "2019-01-23T01:26:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobby](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nobby](https://discourse.gohugo.io/u/nobby)\
**Post date:** [January 23, 2019, 1:26am UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/1 "2019-01-23T01:26:47Z")

</div>

I’ve got a few post titles that start with a lower case letter and others that have an upper case letter. I want to sort `.Title` in the correct order regardless of case.

When I do `range site.RegularPages` the sorting is messed up because of the different cases, like so `Ab, Ba, ab`. I want it to be `ab, Ab, Ba`

How you handle this? I found a previous discussion about this [here](https://discourse.gohugo.io/t/sort-posts-by-title-case-insensitive/6076). But I don’t follow the implementations and looking to see if there is another workaround since that thread is from last year.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [January 23, 2019, 2:03am UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/2 "2019-01-23T02:03:04Z")

</div>

Doing:

```nohighlight
{{ range sort .Pages.Reverse ".Params.Title" }}

```

Will get you:

```nohighlight
Ab ab Ba ba

```

Which is closer to what you want, but not all the way there.

---

<div class="post-metadata">

**Author:** ![nobby](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nobby](https://discourse.gohugo.io/u/nobby)\
**Post date:** [January 23, 2019, 5:32pm UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/3 "2019-01-23T17:32:04Z")

</div>

Tried your your code, but it gives: `ba, ab, Ba, Ab`

Is there a way to use `lower`, like below as this would solve the problem.

```auto
{{ range sort .Pages (lower ".Params.Title") }}

```

Using `lower` gives an error message: `<sort .Pages (lower "...>: error calling sort: params is an unexported field of struct type *hugolib.Page`

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [January 23, 2019, 5:41pm UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/4 "2019-01-23T17:41:18Z")

</div>

> [@nobby](#):
>
> Tried your your code, but it gives: `ba, ab, Ba, Ab`

Did you try it exactly as-is? Because I’m not seeing that.

Edit: When testing this, I named my content files: `1.md`, `2.md`, `3.md`, and `4.md`. Then gave them the titles you mentioned. So not sure if this is making a difference.

---

<div class="post-metadata">

**Author:** ![nobby](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nobby](https://discourse.gohugo.io/u/nobby)\
**Post date:** [January 23, 2019, 5:50pm UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/5 "2019-01-23T17:50:13Z")

</div>

Copied your code directly, and even just renamed my content files to match what you had done. Still get: `ba, ab, Ba, Ab.

My thinking is that in order to sort the content files correctly, all titles need to be converted to lower case, and then somehow range through those, but output the original titles.🤔

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [January 23, 2019, 7:13pm UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/6 "2019-01-23T19:13:53Z")

</div>

@nobby After a bit of poking around, I may have something for you. Give this a shot:

```nohighlight
{{ $list := slice }}

{{ range .Pages }}
  {{ $titleLower := lower .Title }}
  {{ $list = $list | append (dict "titleLower" $titleLower "page" .) }}
{{ end }}

{{ range sort $list ".titleLower" }}
  {{ .page.Title }}
{{ end }}

```

For me, it outputs:

```nohighlight
ab
Ab
ba
Ba

```

---

<div class="post-metadata">

**Author:** ![nobby](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nobby](https://discourse.gohugo.io/u/nobby)\
**Post date:** [January 23, 2019, 8:01pm UTC](https://discourse.gohugo.io/t/how-do-you-do-case-insensitive-list-sorting/16548/7 "2019-01-23T20:01:23Z")

</div>

@zwbetz This works great. 👏
