Do the same thing we discussed in your last topic:
https://discourse.gohugo.io/t/filter-an-array-of-ascii-words-based-on-word-length/40586
Front matter example
dictionary = ['APPLE','banana','cherry']
letterList = ['A','c']
Build an array of maps (words/letters normalized to lower case)
{{ $words := slice }}
{{ range .Params.dictionary }}
{{ $words = $words | append (dict
"word" (. | lower)
"length" (. | len)
"firstLetter" (substr . 0 1 | lower)
"lastLetter" (substr . -1 | lower)
)
}}
{{ end }}
To visualize the resulting data structure you can do:
<pre>{{ jsonify (dict "indent" " ") $words }}</pre>
It looks like this:
[
{
"firstLetter": "a",
"lastLetter": "e",
"length": 5,
"word": "apple"
},
{
"firstLetter": "b",
"lastLetter": "a",
"length": 6,
"word": "banana"
},
{
"firstLetter": "c",
"lastLetter": "y",
"length": 6,
"word": "cherry"
}
]
List words starting with…
{{ range $letter := .Params.letterList | sort }}
{{ with where $words "firstLetter" "eq" (lower .) }}
<p>Words starting with {{ $letter | upper }}</p>
<ul>
{{ range . }}
<li>{{ .word }}</li>
{{ end }}
</ul>
{{ end }}
{{ end }}
List words ending with…
{{ range $letter := .Params.letterList | sort }}
{{ with where $words "lastLetter" "eq" (lower .) }}
<p>Words ending with {{ $letter | upper }}</p>
<ul>
{{ range . }}
<li>{{ .word }}</li>
{{ end }}
</ul>
{{ end }}
{{ end }}