Are arrays a type in Hugo?

In the docs, whenever a function takes a collection, the articles always mention arrays, maps, and slices. Examples:

Are arrays actually a type in Hugo? Aren’t they all slices?

If the answer is no, then every mention of arrays could be removed from the docs (and probably should).

arrays are slices and maps. slices are one-dimensional arrays, maps are two dimensional arrays.

fruits are pears and apples. apples are green and pears are yellow. if you eat or cut them (first/apply) they are gone or cut into parts :wink:

Thanks @pkollitsch for the answer, it made me realize that I asked the wrong question, so I reworded the title to be more precise.

(Previous title was: “Are arrays a thing in Hugo?”)

I think it’s a collective term for “many things in one box”. Slices and maps are types. And those two types are what we call an array (more than one item of things in a single variable).

It’s unlikely to be a collective term because we already use the word “collection” for that. I think that the word creeps from Go, where it’s common to range through “array, pointer to an array, slice, string, map, or channel”.
If it is a Go-ism, then it doesn’t belong to in the docs :upside_down_face:

What’s Go-ism? Who is “we” when we talk about “collective terms”? Is Hugo only for people versed in Go? Let’s add THAT to the docs then. If not, let’s use a language that developers from all kind of software languages understand.

If in doubt, add an item to a glossary. It’s not a Go-ism (whatever that means) because it’s a term for a collection. Call it collection, call it array, call it thingy with items in it. Call it two-dimensional matrix.

At no point does the documentation imply that “array” is something you can typecast. It always states that what is happening can be happening to single- and multi-dimensional arrays. collections. matrixes.

Other than that: Go to and add a pull request to change it and see what is happening. I think the documentation omits too much. A nerd coming from PHP needs to understand what first/apply/delimit does. If your PR does improve that it will be merged. This whole “we need one single term to describe our religion” will lead to nothing if this is a project for people of “all over the programming languages world”.

And about that “go-ism”: **Were you able to implement the functionality you required using the documentation? If not, why? Could it be solved with practical examples? Add a PR :slight_smile: **

And please: how do I do an inverted smiley?

PS: wait until you debug a page object (not sure if it’s called that in Go lingo, but as someone coming from PHP and JS I understand :slightly_smiling_face: )

The term “COLLECTION” is used in all the function signatures of functions that accept a slice or maps, that’s why I said “we”

The thing is that if the word is not relevant (something that can’t be typecast) then it’s just noise, even if every developer in the world understands what it is.

About the contribution to the Docs, I’m working on something. I’ll keep you posted. In fact, there’s an open issue about overhauling the Docs, so it would be great it you joined the discussion if you think that thet omit too much.

The many emojis are available using the notation
:smile&: (remove the &)

Arrays are a type in Hugo (and slices are technically backed by arrays). Practically, though, almost all of a normal Hugo user’s interactions with that type of data would be in the form of a slice.

Since most people coming from non-Go backgrounds won’t know what a slice is, the docs often use both terms or use them interchangeably (trying to unsuccessfully keep both camps happy).


Thanks for the reply.

I’m now curious about whether or not you can actually get a variable so that {{ printf "%t . }} returns array[4] or something. Maybe with some {{ template }} magic it might be possible, but at what cost? I’ll find out.

1 Like

As far as I know printf is using these formatting values: - there are notes about that, but it goes over my head. It looks like you can actually use something like %#[1]x for an array notation. Let us know what you end up with, eager to learn :slight_smile:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.