Last active
October 25, 2022 22:12
-
-
Save Bat-Chat/02e5123aef8cfe24d5a69cc8900882c2 to your computer and use it in GitHub Desktop.
getting linklist json in shopify through liquid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% layout none %} | |
{ | |
"parent":[ | |
{% for link in linklists.main-menu.links %} | |
{% if link.type == 'collection_link' %} | |
{% assign parentObj = link | map: 'object' %} | |
{% assign parentId = parentObj[0].id %} | |
{"id":"{{ parentId }}", "title":"{{ link.title }}", "handle":"{{ link.handle }}"} | |
{% else %} | |
{} | |
{% endif %} | |
{% if forloop.last == false %},{% endif %} | |
{% endfor %} | |
], | |
"child":[ | |
{% for link in linklists.main-menu.links %} | |
{% if link.type != 'collection_link' %} | |
{% continue %} | |
{% endif %} | |
{% assign parentObj = link | map: 'object' %} | |
{% assign parentId = parentObj[0].id %} | |
{% for child in link.links %} | |
{% assign childObj = child | map: 'object' %} | |
{"id":"{{ childObj[0].id }}", "parent_id":"{{ parentId }}", "title":"{{ child.title }}", "handle":"{{ child.handle }}"} | |
{% if forloop.last == false %},{% endif %} | |
{% endfor %} | |
{% if link.links != blank %} | |
{% if forloop.first == true %},{% endif %} | |
{% endif %} | |
{% endfor %} | |
], | |
"sub_child":[ | |
{% for link in linklists.main-menu.links %} | |
{% if link.type != 'collection_link' %} | |
{% continue %} | |
{% endif %} | |
{% for child in link.links %} | |
{% assign childObj = child | map: 'object' %} | |
{% assign childId = childObj[0].id %} | |
{% for subChild in child.links %} | |
{% assign subChildObj = subChild | map: 'object' %} | |
{"id":"{{ subChildObj[0].id }}", "parent_id":"{{ childId }}", "title":"{{ subChild.title }}", "handle":"{{ subChild.handle }}"} | |
{% if forloop.last == false %},{% endif %} | |
{% endfor %} | |
{% if forloop.last == false %},{% endif %} | |
{% endfor %} | |
{% endfor %} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment