Re: Calling a linklist with a variable for a 4 level linklist

Calling a linklist with a variable for a 4 level linklist

54321
Visitor
2 0 0

I am using linklists to display structured content on a page. I need an extra level of hierarchy than shopify navigation allows. So I have one linklist (list1) that is a single level deep and has all of the top level categories with an additional corresponding linklist for each item in list1. The handle for each corresponding linklist matches the link handle for each item in list1

 

I have been trying to write a loop that renders a link in list1 then uses the handle from that link to call the linklist that corresponds to it and render the appropriate links, children, and grandchildren.

 

The snippet i'm using to call the corresponding linklist works when hardcoded but doesn't work when I try to pass it a variable. The handles for all the related linklist have been double checked and I've also confirmed that the variable handle is being passed to the snippet.

 

code on the page:

 <ul class="menu top-level">
      {% for link in linklists.list1.links %}
        <li class="menu-link">
        <a href="{{ link.url }}">{{ link.title }}</a>
        
        {% assign listhandle = link.handle %}
        {% include "linklist" with linklistHandle: listhandle %}
       </li>
     {% endfor %}
</ul>

code in a linklist snippet:

 

{% for link in linklists[linklistHandle].links %}
  <li class="menu-link">
    <a href="{{ link.url }}">{{ link.title }}</a>
    ...

 

 

 

 

Replies 2 (2)

54321
Visitor
2 0 0

bump

justinmeyer
Shopify Partner
1 0 0

I ran into something similar where a handle I knew was correct wasn't indexing properly into the linklists object. I think there is some sort of bug on shopify's side because I worked around it by running my handle through the downcase filter. This should obviously do nothing but doing the equivalent of the following: 

{% assign listhandle = link.handle | downcase %}:  

fixed the problem for me.