github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/sort.md (about)

     1  ---
     2  title: sort
     3  # linktitle: sort
     4  description: Sorts maps, arrays, and slices and returns a sorted slice.
     5  godocref:
     6  date: 2017-02-01
     7  publishdate: 2017-02-01
     8  lastmod: 2017-02-01
     9  categories: [functions]
    10  menu:
    11    docs:
    12      parent: "functions"
    13  keywords: [ordering,sorting,lists]
    14  signature: []
    15  workson: [lists,taxonomies,terms,groups]
    16  hugoversion:
    17  relatedfuncs: []
    18  deprecated: false
    19  aliases: []
    20  ---
    21  
    22  A sorted array of map values will be returned with the keys eliminated. There are two optional arguments: `sortByField` and `sortAsc`. If left blank, sort will sort by keys (for maps) in ascending order as its default behavior.
    23  
    24  ```
    25  +++
    26  keywords: [ "tag3", "tag1", "tag2" ]
    27  +++
    28  
    29  // Site config
    30  +++
    31  [params.authors]
    32    [params.authors.Derek]
    33      "firstName"  = "Derek"
    34      "lastName"   = "Perkins"
    35    [params.authors.Joe]
    36      "firstName"  = "Joe"
    37      "lastName"   = "Bergevin"
    38    [params.authors.Tanner]
    39      "firstName"  = "Tanner"
    40      "lastName"   = "Linsley"
    41  +++
    42  ```
    43  
    44  ```
    45  // Use default sort options - sort by key / ascending
    46  Tags: {{ range sort .Params.tags }}{{ . }} {{ end }}
    47  
    48  → Outputs Tags: tag1 tag2 tag3
    49  
    50  // Sort by value / descending
    51  Tags: {{ range sort .Params.tags "value" "desc" }}{{ . }} {{ end }}
    52  
    53  → Outputs Tags: tag3 tag2 tag1
    54  
    55  // Use default sort options - sort by value / descending
    56  Authors: {{ range sort .Site.Params.authors }}{{ .firstName }} {{ end }}
    57  
    58  → Outputs Authors: Derek Joe Tanner
    59  
    60  // Use default sort options - sort by value / descending
    61  Authors: {{ range sort .Site.Params.authors "lastName" "desc" }}{{ .lastName }} {{ end }}
    62  
    63  → Outputs Authors: Perkins Linsley Bergevin
    64  ```
    65