I’m building a page that serves a list of speakers for a conference we’re putting on, and one of the params in the front matter is featured, which has a value of either true or false.
e.g.:
+++
name = "Frank Spellman"
bio = ""
id = 697227
title = "VP of Engineering"
featured = true
organization = "ThingCorp"
sessions = []
[[resources]]
name = "headshot"
src = "headshot.jpg"
+++
I’d like to be able to sort so that featured speakers are in the top of my list and the rest of the speakers follow but I have not had any luck getting sort to work for me using this:
{{ range sort $speakers ".Params.featured" }}
...
{{ end }}
This doesn’t seem to have any effect, but seems to be limited to boolean params as if I sort by name alone using
{{ range sort $speakers ".Params.name" }}
...
{{ end }}
then it works as expected.
I’ve searched but I haven’t found anything related (though searching for sort and bool doesn’t exactly narrow down results very well since they’re such core concepts of most development).
Are there any limitations with sorting by bool’s in frontmatter? Would I be better served changing them to integers 0 and 1?
@zwbetz hmm, interesting. I wouldn’t have thought of doing that. Right now all my speakers are living under content/speakers/<speaker-name-slug/ where each speaker had a directory for containing their index.md with frontmatter.
I’m not sure I understand the benefits of splitting into sets here. Could you help me understand?
I’m currently using the featured boolean approach successfully on our front page where I’m only showing the featured speakers using
@zwbetz that worked perfectly. Thank you! I’m still confused as to why the sort wasn’t working the way I expected but I’m very thankful for the quick solution!