Research: why `menus` object returns different values for the same key

New Member
1 0 0

I have a question about object `menus` which is similar to `linklist`. It is not documented in Shopify, but it works and has an interesting behavior. The question is not about how to create the properly code (I'm experienced developer). It just aroused my curiosity, so I'm here.


There is a piece of code which is calling in "bags" collection page:


{% for link in linklists.main-menu.links %}

{% if collection.handle == link.handle %} <p>test</p> {% endif %}

{% assign linkTitleHandleize = link.title | handleize %}

{% comment %} The interesting thing is coming from here: {% endcomment %} <p>menu[collection.handle] returns {{ menus[collection.handle] }}</p> <p>menu["bags"] returns {{ menus["bags"] }}</p> <p>menu[link.handle] returns {{ menus[link.handle] }}</p> <p>menu[linkTitleHandleize] returns {{ menus[linkTitleHandleize] }}</p>
{% endfor %}

The HTML output for it is:

menu[collection.handle] returns EmptyDrop
menu["bags"] returns EmptyDrop
menu[link.handle] returns LinkListDrop
menu[linkTitleHandleize] returns LinkListDrop

As developers may know, these things are equal:

collection.handle = link.handle = linkTitleHandleize = "bags"

For example, you may see that <p>test</p> is in our HTML output, so collection.handle = link.handle


The main question is why the `menus` object's output is different (EmptyDrop vs LinkListDrop) for the same access keys: `collection.handle` and `link.handle` which are actually just  the  "bag" string? Why Liquid works so strange with it? Again, I know that `menus` is undocumented object and developers may skip that question, but if you're interested as me, let's do that research.


Thank you!




Shopify Partner
1353 20 188

@webmaxer I am always happy to see new Liquid objects/additions.

However in this case I am unable to replicate (sorry may be tired and old).


Are you sure the menu isn't somewhere assigned as a variabile?


Thanks tips, tricks & Shopify sections