Hello, everyone! I have a problem, hope someone can help me with solution, I can’t find for hours. What I need is sort range of data files by variable, and after that do another sort by another variable. I will show, what I am trying to do.
{{ range sort (sort .Site.Data.portfolio_residential “project_name”) “favorite”}}
{{ end }}
favorite: “2”
project_name: Betesh
picture: /assets/images/public/BET_200220_07.jpg
address: Brooklyn, NY
So I want to get list of favorites. Favorites could be from 1 to 7. It looks like: if from 1 to 6, they are on the top by numerous order. If “favorite” is 7, use alphabet order. Now it looks strangely. Favorites are on the top, but alphabet looks a bit wrong, also if I add one more item f.e. with favorite - “1” (so they are two with same number) on the top appears not alphabetically first…
A bit complicated description, sorry. Would be glad for any help! Thanks for your time!
To be more clear:
This sorting works. F.e. if I remove parameter “project_name”, and leave only “favorite”, the items with parameter = 7 are created randomly each time.
With both parameters, it stops creating randomly, but order is strange, mostly alphabetical, but some items are not in their places. I wondering what I am doing wrong, the second parameter is correct and checked, there are no mistakes… Still need some help, guys!
{{/* Build slice of unique, sorted favorites. */}}
{{- $favorites := slice -}}
{{- range .Site.Data.portfolio_residential -}}
{{- $favorites = $favorites | append .favorite -}}
{{- end -}}
{{- $favorites = $favorites | uniq | sort -}}
{{/* Range over the sorted favorites, then range over a sorted subset of the data file. */}}
{{- range $favorites -}}
{{- range where (sort $.Site.Data.portfolio_residential "project_name" "asc") "favorite" . -}}
favorite = {{ .favorite }}<br>
project_name = {{ .project_name }}<br><br>
{{- end -}}
{{- end -}}