Convenience functions for isfirstitem and/or islastitem



I recently had to check for the last item in a range and was expecting some kind of convenience function or something but there isn’t one yet.
I then found this thread about it. The solutions posted there work great but it is still weird to read in my opinion and I think having such convenience functions to access the first or last item in an array will help a lot and isn’t totally uncommon.

Would there be any interest in adding these to Hugo?

An example would be:

{{ range first 10 (where .Site.RegularPages "Section" "blog") }}
{{ if islastitem }}
    <h1>I'm the last item!</h1>
{{ end }}

Thanks for all the hard work!!


I suspect something like that would have to be added to Go’s std library, and I doubt that this passes their “bar ofr importance”, but you can try: