As near as I’ve been able to tell through countless google searches, this doesn’t seem to be possible, but in the event my google-fu is just bad, I’ll directly ask here.
(Disclaimer: I am not Hugo proficient, per se, but once upon a time I did a lot of self-hosted Moveable Type and WordPress blogging so I have enough general templating/theming experience to probably be able to follow along here.)
Currently over on micro.blog each of my blog posts displays the categories I’ve filed it in, using this code (which I don’t even remember where I found).
{{ range .Params.categories }}<a href="{{ "/categories/" }}{{ . | urlize }}">{{ . }}</a> {{ end }}
Is there no way, via sort or otherwise, to get these to display alphabetically? Weirdly, if I just add sort after range is does work but it also throws up template errors in my micro.blog account.
Theme error: Error building site: failed to render pages: render of "page" failed: "/bix_504e91/layouts/post/single.html:17:12": execute of template failed: template: post/single.html:17:12: executing "main" at : error calling sort: sequence must be provided
While this error doesn’t, for some reason, actually seem to stop the page in question from rendering do seem to cause trouble elsewhere, but mostly I just assume that if it’s barfing up an error at all, despite working, I shouldn’t do it.
Which does output [Architecture Design Technology] but how do I incorporate this idea into the original {{ range .Params.categories }}<a href="{{ "/categories/" }}{{ . | urlize }}">{{ . }}</a> {{ end }} code above, to result in a list of linked tag pages?
I’m not sure what else to explain. Existing code lists the categories the blog post is in, but I can’t seem to find any method, or anyone else who has found any method, for having them display alphabetically.
I have no idea what Hugo version; as noted, this is on a Micro.blog blog; I don’t have access to that info. (I’m having similar discussions in the Micro.blog Slack, also to no avail.)
It’s literally this theme with the above {{ range .Params.categories }}<a href="{{ "/categories/" }}{{ . | urlize }}">{{ . }}</a> {{ end }} code added to the ‘single.html’ template.
FWIW, I’ve since asked M.b their current Hugo version and they are still back on 0.53. I don’t know if there’s something in later versions which allow sorting tags alphabetically on a post.
Okay, well, it worked in one Marfa edit and not another Marfa edit, but that fact and @ju52’s post led me to the why: if I in fact use even just my original code, but wrap it in an{{ if .Params.categories }} {{ end }} it all works, with no error messages about template builds. I don’t understand enough about any of this to understand why that fixes it, but it does.