Hugo has a really good menu system. However, I was wondering about a particular behaviour, which is ordering when no weights are set.
For example, say I have this menu defined:
- name: Item 4
- name: Item 3
- name: Item 2
- name: Item 1
Normally, if I range through
site.Menus.main, I would be expecting items in the order of the slice, i.e. Item 4, Item 3, …, Item 1. However, Hugo returns a lexicographically sorted slice instead, i.e. Item 1, …, Item 4.
I don’t understand why Hugo ignores the slice order (there’s probably a good reason for this), but adding weight for each item seems redundant.
Adding the weight doesn’t
seems redundant, it’s a good way to specify how you want your menu ordered.
If you do not specify that it shall do in order you specified (Menus | Hugo) but if not, then or you found a bug our your template when rendering theme is doing sorting somehow when displaying it.
I have the exact same issue as @UtkarshVerma , I created a theme from scratch and the issue is present , I was forced to use
weight to choose the right order.
In some sense we do respect the slice order, but just in situations where two items sort equally, which is … rare.
The main reason for this sorting is that there isn’t just 1 source for these menu items, so they somehow need to be merged (so there isn’t just 1 slice order).
Yeah, that would make sense.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.